diff --git a/plugins/title/title.plugin.zsh b/plugins/title/title.plugin.zsh new file mode 100755 index 0000000..a403b7a --- /dev/null +++ b/plugins/title/title.plugin.zsh @@ -0,0 +1,60 @@ +#!/bin/zsh + +setopt extended_glob + +function print_title() { + if [ -n "$SSH_CONNECTION" ]; then + print -Pn "(%n@%m) " + fi + + print -Pn "$*" +} + +# Define a title function per terminal +case "$TERM" in +# GNU Screen: +( screen | screen.* | screen-* ) + function title { + print -Pn "\ek" + print_title $* + print -Pn "\e\\" + print -Pn "\e]2;" + print_title $* + print -Pn "\a" + } +;; + +# X terminals +( *xterm* | *rxvt ) + function title { + print -Pn "\e]2;" + print_title $* + print -Pn "\a" + } +;; +* ) + function title { + # Unknown terminal, do nothing. + } +esac + +# Override precmd function to display status code if non-zero and update title +# with path, and hostname if remote +function precmd { + # Get return code and display it if non-zero + retcode=$? + if [ $retcode -ne 0 ]; then + # TODO check termcap to see if we can use color + print -P "\e[01;31m -- Non zero exit: $retcode --\e[0m" + fi + + # Show the current directory in title. + title "%~" +} + +function preexec () { + emulate -L zsh + local -a cmd; cmd=(${(z)1}) + title $cmd[1]:t "$cmd[2,-1]" +} +