From 731394c0c1172b80563c8f3a51e69d5a1e0f96ff Mon Sep 17 00:00:00 2001 From: Alexis Lahouze Date: Tue, 29 Oct 2013 09:42:59 +0100 Subject: [PATCH] Added title plugin. --- plugins/title/title.plugin.zsh | 60 ++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 plugins/title/title.plugin.zsh 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]" +} +