#!/bin/bash # # Version: 1.0 3/30/2007 # Author: Martin Fick # Copyright License: GNU GPL2 # This simple program will keep track of your latest display # if it is set and it will return the last known value if it # is unset. Use this in environments where you want your # display to automatically get set whenever you log into # remote machines. Appropriate stderr messages are output # so that you are aware of your settings. # # This display value gets stored in ~/.xdisplay # To use, put this in your path somewhere, say ~/bin and: # # In csh, do: setenv DISPLAY `xdisplay` # # In sh, do: export DISPLAY `xdisplay` # d_read() { cat "$DB" } d_write() { echo "$1" > "$DB" chmod go-w "$DB" } d_fix() { if [ ! -z $(echo "$1"|grep '^:') ] ; then echo "$(hostname)$1" else echo "$1" fi } DB=/usr2/qmarfic/.xdisplay if [ -z "$DISPLAY" ] ; then if [ -f "$DB" ] ; then DISPLAY=$(d_read) DISPLAY=$(d_fix "$DISPLAY") echo "Display unset, setting to $DISPLAY" >&2 echo "$DISPLAY" exit fi read "DISPLAY is unset, please set it now:" DISPLAY DISPLAY=$(d_fix "$DISPLAY") echo "Display unset, setting to $DISPLAY" >&2 else DISPLAY=$(d_fix "$DISPLAY") echo "Display set, writting $DISPLAY to DB" >&2 fi d_write "$DISPLAY" echo "$DISPLAY"