title revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase# add to (+), delete from (-), set [=], or print (.) window title
5c4c13ac875d79def115ce3d8443d4ec87b3252aJulian Kornberger# arguments are eval'd before printing
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase# title text string exported in TITLE_TEXT
d62eba79f306957dd89ea9d3313600e98e2a8bebJulian Kornberger
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehasefunction title # [ + | - | = | . ] title ...
5c4c13ac875d79def115ce3d8443d4ec87b3252aJulian Kornberger{
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase typeset x t="$TITLE_TEXT"
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa
6aabfa7c6755eb714a27d764c3d6dea2692fcb43Eugen Kuksa case $1 in
95cb759dc990efae933531ee5c54d476bb13d8e9Eugen Kuksa +) shift
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa case $# in
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa 0) ;;
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa *) for x
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa do case " $t " in
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa *" $x "*) ;;
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa " ") t=$x ;;
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa *) t="$t $x" ;;
95cb759dc990efae933531ee5c54d476bb13d8e9Eugen Kuksa esac
95cb759dc990efae933531ee5c54d476bb13d8e9Eugen Kuksa done
95cb759dc990efae933531ee5c54d476bb13d8e9Eugen Kuksa case $t in
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa $TITLE_TEXT) return 1 ;;
3df59f8f57e90e1667f4c31d77accbe2b4910c1cEugen Kuksa esac
d62eba79f306957dd89ea9d3313600e98e2a8bebJulian Kornberger ;;
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase esac
0b611cf877554b1aa910fa23099220f2d1d15e89Julian Kornberger ;;
0b611cf877554b1aa910fa23099220f2d1d15e89Julian Kornberger -) shift
d62eba79f306957dd89ea9d3313600e98e2a8bebJulian Kornberger case $# in
6d67b58472abc76a1d0d68a1d1fa32a45dc6626aJulian Kornberger 0) ;;
6d67b58472abc76a1d0d68a1d1fa32a45dc6626aJulian Kornberger *) for x
d62eba79f306957dd89ea9d3313600e98e2a8bebJulian Kornberger do case " $t " in
d62eba79f306957dd89ea9d3313600e98e2a8bebJulian Kornberger *" $x "*) t="${t%?( )$x*}${t##*$x?( )}" ;;
be6eb5d7ea1888f2f835fe0fff358f72572afeb4henning mueller esac
be6eb5d7ea1888f2f835fe0fff358f72572afeb4henning mueller done
be6eb5d7ea1888f2f835fe0fff358f72572afeb4henning mueller case $t in
be6eb5d7ea1888f2f835fe0fff358f72572afeb4henning mueller $TITLE_TEXT) return 1 ;;
ee5342a8882c2fc7631fcffb5497e6597747887cTim Reddehase esac
d62eba79f306957dd89ea9d3313600e98e2a8bebJulian Kornberger ;;
esac
;;
.) print -r -- "$TITLE_TEXT"
return 0
;;
=) shift
t="$*"
;;
*) t="$*"
;;
esac
export TITLE_TEXT="$t"
eval x=\"$t\"
case $TERM in
630*) print -nr -- $'\E[?'"${#x}"$';0v'"${x}" ;;
uwin*|*vt100|xterm*) print -nr -- $'\E]0;'"${x}"$'\a' ;;
*) return 1 ;;
esac
return 0
}