#!/bin/sh -u # # Generic open-a-window. # # Default location is tuned to my X11 setup (i.e. 103 pixels down from # the top of the screen). # The -big option is tuned to my X setup on a 1280x1024 screen. # - Cameron Simpson December 1991 # : ${TMPDIR:=/tmp} : ${LOGDIR:=$HOME/var/log} : ${SHELL:=/bin/sh} : ${TERMOPTIONS:=''} : ${WINJOB:=''} : ${XAUTHORITY:=''} : ${PREFTERM:=xterm} : ${DISPLAY:=''} : ${X11_COMPOSITE:=''} : ${TERM:=dumb} : ${TERMSHADE:=''} : ${TERMTINT:=''} : ${TERMOPTIONS:=''} : ${RXVT_SOCKET:=/tmp/urxvtd-socket-$USER} : ${OS:=`uname -s | tr '[A-Z]' '[a-z]'`} export RXVT_SOCKET TMPDIR cmd=`basename "$0"` usage="Usage: $cmd [-v] [-w width] [-h height] [-x x-pos] [-y y-pos] [-l lock] [-1 lock] [-j job] [-f font] [-n name] [-big] [-small] [-keepio] [-xauthhack] [-tab] [-window] [{-c shellcmd}/{-e exec-list}/{-- raw-args}]" windowmode=tab trace= termopts= xrmopts= dotrans= detach='exec >/dev/null &2 badopts=1 shift; break ;; esac case $1 in --) shift; break ;; -e) shift; break ;; -c) shcmd=$2; shift; shift set -- ${1+"$@"} -e "$SHELL" -c "$shcmd" ;; -a) async=1 ;; +a) async= ;; -l) lock=$2; shift ;; -1) lock1=$1 lock=$2; shift ;; -j) WINJOB=$2; shift; export WINJOB ;; -ip) dotrans=1 ;; +ip) dotrans= ;; -sh) shade=$2; shift ;; -C|-iconic) termopts="$termopts $1" ;; -fg|-bg) termopts="$termopts $1 $2"; shift ;; -v) set -x ;; -w) w=$2 ; shift ;; -h) h=$2 ; shift ;; -x) x=$2 ; shift ;; -y) y=$2 ; shift ;; -n|-T) title=$2 ; shift ;; -f) f=$2 ; shift ;; -env) exec genv TERMOPTIONS TERMTINT TERMSHADE ;; -big) sized=1 x=$bigx y=$bigy w=$bigw h=$bigh f=$bigf ;; -small) sized=1 x=$smallx y=$smally w=$smallw h=$smallh f=$smallf ;; -keepio) detach= ;; -xauthhack) xauthhack=1 ;; -tab) windowmode=tab ;; -window) windowmode=window ;; -g|-geometry)sized=1 geometry=$2; shift ;; -xrm) xrmopts="$xrmopts $1 "`shqstr "$2"`; shift ;; --) shift; break ;; -?*) echo "$cmd: unrecognised option: $1" >&2 badopts=1 ;; *) break ;; esac shift done [ $badopts ] && { echo "$usage" >&2; exit 2; } [ $# = 0 ] && set -- "$SHELL" [ -n "$title" ] || title=$* # suppress lock if none needed [ -n "$lock" ] && set -- lock $lock1 "$lock" -- "$@" set -- ttysane "$@" [ -n "$WINJOB" ] && set -- winjob "$WINJOB" "$@" case "$TERM,$DISPLAY" in *,?*) if [ -n "$X11_COMPOSITE" ] then qcmd=`shqstr "$@"` set -- sh -c "( exec >/dev/null; sleep 2; xwin-transset \"\$WINDOWID\" ) & exec $qcmd" fi case "$PREFTERM" in gnome-terminal) termopts="$termopts --title \"\$title\" $xrmopts" ;; aterm) termopts="$termopts -title \"\$title\"" ;; urxvt*) termopts="$termopts -title \"\$title\" $xrmopts" case "$f" in '' | [0-9]x* | [1-9][0-9]x* | -* ) ;; *) f=xft:$f ;; esac ;; *) termopts="$termopts -title \"\$title\" $xrmopts" ;; esac [ -n "$f" ] && termopts="$termopts -fn \"\$f\" -fb \"$f\"" case $x in +*|-*) ;; *) x=+$x ;; esac case $y in +*|-*) ;; *) y=+$y ;; esac if [ $sized ] then case "$geometry" in # specify tab M) geometry=${X11_TABMIDDLE_DXC}x${TTY_HIGH}+${X11_TABMIDDLE_X}-0 ;; [0-9]) eval "geometry=\${X11_TAB${geometry}_DXC}x\${TTY_HIGH}+\${X11_TAB${geometry}_X}-0" ;; '') geometry=${w}x${h}$x$y ;; esac termopts="$termopts -geometry \"\$geometry\"" fi if [ -n "$xauthhack" -a -n "$XAUTHORITY" -a -r "$XAUTHORITY" ] then # Fight with NFS/xterm brain damage. xauth=$TMPDIR/$cmd.$$ exec 4>$xauth chmod 600 $xauth cat <"$XAUTHORITY" >&4 exec 4>&- XAUTHORITY=$xauth export XAUTHORITY fi case "$PREFTERM" in rxvt) if [ $dotrans ] then termopts="$termopts -ip" else termopts="$termopts +ip" fi ;; urxvt*) if [ $dotrans ] then termopts="$termopts -ip" [ -n "$tint" ] && termopts="$termopts -tint $tint" [ -n "$shade" ] && termopts="$termopts -sh $shade" else termopts="$termopts +ip" fi [ $async ] || PREFTERM=urxvt # gotta be synchronous case "$PREFTERM" in urxvtc) if [ -n "$RXVT_SOCKET" ] || RXVT_SOCKET=`rig-urxvtd` then export RXVT_SOCKET else PREFTERM=urxvt fi ;; esac ;; aterm) # -fade 90 if [ $dotrans ] then termopts="$termopts -tr" [ -n "$shade" ] && termopts="$termopts -sh $shade" else termopts="$termopts +tr" fi ;; esac case "$PREFTERM" in gnome-terminal) eval "set -- \$PREFTERM $termopts -x \"\$@\"" ;; *) eval "set -- \$PREFTERM $termopts -e \"\$@\"" ;; esac ;; iris-ansi*,*) [ -n "$f" ] && set -- -f "$f" "$@" [ -n "$x$y" ] && set -- -p "$x,$y" "$@" [ -n "$w$h" ] && set -- -s "$w,$h" "$@" [ -n "$title" ] && set -- -t "$title" -n "$title" "$@" set -- wsh -v "$@" ;; *) if [ "x$OS" = xdarwin ] then runme=$TMPDIR/$cmd.$$.sh qrunme=`shqstr "$runme"` qcmd=`shqstr "$@"` wd=`/bin/pwd` qwd=`shqstr "$wd"` ( echo '#!/bin/sh' dumpenv -f -sh printf "%s\n" ": set -x; rm -f $qrunme; cd $qwd; exec $qcmd" ) >"$runme" chmod u+rx "$runme" case $windowmode in tab) itermterm='current terminal' ;; window) itermterm='make new terminal' ;; *) echo "$cmd: unsupported windowmode \"$windowmode\"" >&2 exit 2 ;; esac set -- \ osascript \ -e 'tell app "iTerm" activate set myterm to ('"$itermterm"') tell myterm set mysession to (make new session at the end of sessions) tell mysession set name to "'"$title"'" exec command "'"$runme"'" end tell end tell end tell' else async= detach= fi ;; esac ##set -x eval "$detach" eval "$closefds" ##exec 2>>$HOME/var/log/alert [ $async ] && set -- bgproc -p - -- "$@" exec "$@"