1*da2e3ebdSchin# add to (+), delete from (-), set [=], or print (.) window title 2*da2e3ebdSchin# arguments are eval'd before printing 3*da2e3ebdSchin# title text string exported in TITLE_TEXT 4*da2e3ebdSchin 5*da2e3ebdSchinfunction title # [ + | - | = | . ] title ... 6*da2e3ebdSchin{ 7*da2e3ebdSchin typeset x t="$TITLE_TEXT" 8*da2e3ebdSchin 9*da2e3ebdSchin case $1 in 10*da2e3ebdSchin +) shift 11*da2e3ebdSchin case $# in 12*da2e3ebdSchin 0) ;; 13*da2e3ebdSchin *) for x 14*da2e3ebdSchin do case " $t " in 15*da2e3ebdSchin *" $x "*) ;; 16*da2e3ebdSchin " ") t=$x ;; 17*da2e3ebdSchin *) t="$t $x" ;; 18*da2e3ebdSchin esac 19*da2e3ebdSchin done 20*da2e3ebdSchin case $t in 21*da2e3ebdSchin $TITLE_TEXT) return 1 ;; 22*da2e3ebdSchin esac 23*da2e3ebdSchin ;; 24*da2e3ebdSchin esac 25*da2e3ebdSchin ;; 26*da2e3ebdSchin -) shift 27*da2e3ebdSchin case $# in 28*da2e3ebdSchin 0) ;; 29*da2e3ebdSchin *) for x 30*da2e3ebdSchin do case " $t " in 31*da2e3ebdSchin *" $x "*) t="${t%?( )$x*}${t##*$x?( )}" ;; 32*da2e3ebdSchin esac 33*da2e3ebdSchin done 34*da2e3ebdSchin case $t in 35*da2e3ebdSchin $TITLE_TEXT) return 1 ;; 36*da2e3ebdSchin esac 37*da2e3ebdSchin ;; 38*da2e3ebdSchin esac 39*da2e3ebdSchin ;; 40*da2e3ebdSchin .) print -r -- "$TITLE_TEXT" 41*da2e3ebdSchin return 0 42*da2e3ebdSchin ;; 43*da2e3ebdSchin =) shift 44*da2e3ebdSchin t="$*" 45*da2e3ebdSchin ;; 46*da2e3ebdSchin *) t="$*" 47*da2e3ebdSchin ;; 48*da2e3ebdSchin esac 49*da2e3ebdSchin export TITLE_TEXT="$t" 50*da2e3ebdSchin eval x=\"$t\" 51*da2e3ebdSchin case $TERM in 52*da2e3ebdSchin 630*) print -nr -- $'\E[?'"${#x}"$';0v'"${x}" ;; 53*da2e3ebdSchin uwin*|*vt100|xterm*) print -nr -- $'\E]0;'"${x}"$'\a' ;; 54*da2e3ebdSchin *) return 1 ;; 55*da2e3ebdSchin esac 56*da2e3ebdSchin return 0 57*da2e3ebdSchin} 58