#!/bin/ksh # @(#) Determine X display if possible #..# systems: #..# sites: tag=${0##*/} tmp=/tmp/${tag}$$ rm -f $tmp set -A AWK $(whence nawk) [ ${#AWK[*]} -gt 0 ] && alias awk=$AWK usage="Usage: $tag [-sh|-ksh|-csh]" while [ $# -gt 0 ]; do case "$1" in -v|-x) set "$1" ;; -vi) vi $0; exit ;; -about) echo "$tag was written by David Ledger" echo "dledger@ivdcs.demon.co.uk" exit ;; -h) echo "$usage" echo "" echo "$tag searches back up the process tree until a process" echo "which includes a 'DISPLAY=' string in its ps -f" echo "listing or process 1 is found. If the display setting is" echo "found, it is reported in a form that, if 'exec'd by the" echo "calling shell, would set that shell's DISPLAY environment" echo "variable." echo "" echo "If the string is not found, a message is printed on" echo "stderr." echo "" echo "'-sh', '-ksh' or '-csh' flags will cause the output to be" echo "generated suitable for that shell. The default is to" echo "produce output suitable for \$SHELL." echo "" exit ;; -sh|-ksh|-csh) sh=`expr "$1" : '-\(.*\)'` ;; *) ;; esac shift done d=`awk ' function ckparent(pid) { while ("ps -fp" pid | getline) { if ($1 == "UID") { continue } else if ($2 == 1) { return } else if ($0 ~ /.* -display +[.a-zA-Z0-9_-]+:[0-9].[0-9]/) { for (i=8; i&2" } '