# Last edited on 1999-03-29 22:41:49 by stolfi
# Tries to set the DISPLAY variable from the file ~/.DISPLAY, if unset.
# To be source'd, not run!

# Make sure there is no local DISPLAY shadowing env's DISPLAY:
unset DISPLAY

# Check for common bogus values:
if ( ! $?DISPLAY ) then
  set fixdisp_old = 'undefined'
else
  set fixdisp_old = "${DISPLAY}"
endif

set fixdisp_new = "${fixdisp_old}"

# Check for common bogus values:
if ( ( "x${fixdisp_new}" == "x.0" ) \
  || ( "x${fixdisp_new}" == "x:0.0" ) \
  || ( "x${fixdisp_new}" == "x" ) \
  || ( "x${fixdisp_new}" == "xundefined" ) ) then
  if ( -r ${STOLFIHOME}/.DISPLAY ) then
    set fixdisp_new = "`/bin/cat ${STOLFIHOME}/.DISPLAY`"
    if ( ( "x${fixdisp_new}" == "x.0" ) \
      || ( "x${fixdisp_new}" == "x" ) \
      || ( "x${fixdisp_new}" == "xundefined" ) ) then
      set fixdisp_new = ":0.0"
    endif
  endif
endif

# Now fix DISPLAY and report change:
if ( "x${fixdisp_new}" != "x${fixdisp_old}" ) then
  echo -n "DISPLAY was '${fixdisp_old}'"
  setenv DISPLAY "${fixdisp_new}"
  echo " --- set to '$DISPLAY'"
endif

# Cleanup local variables
unset fixdisp_old
unset fixdisp_new

