Refactor window and tab title in tty
Term window title and tab title are now skinable
Tab title can be different from window title (when supported by term)
Default theme is optimized of usuability (no %u@%m: $~ in a 10 char tab)
Cleanup code duplication and add comment for supported terms
On osX it works great on iterm, and is decent once you tweak Terminal pref
Tested under GNU screen, iTerm and Apple Terminal, need to be tested on linux
TODO implement Konsole support (via dbus)
Diff
1diff --git a/lib/functions.zsh b/lib/functions.zsh
2index 914f2ef25a22d141cfd2e8c9c6255e535641274b..6f5d015f7a598739ddc3de8e5fbf451817a8e125 100644
3--- a/lib/functions.zsh
4+++ b/lib/functions.zsh
5@@ -1,26 +1,3 @@
6-## fixme, i duplicated this in xterms - oops
7-function title {
8- if [[ $TERM == "screen" ]]; then
9- # Use these two for GNU Screen:
10- print -nR $'\033k'$1$'\033'\\\
11-
12- print -nR $'\033]0;'$2$'\a'
13- elif [[ ($TERM =~ "^xterm") ]] || [[ ($TERM == "rxvt") ]]; then
14- # Use this one instead for XTerms:
15- print -nR $'\033]0;'$*$'\a'
16- fi
17-}
18-
19-function precmd {
20- title zsh "$PWD"
21-}
22-
23-function preexec {
24- emulate -L zsh
25- local -a cmd; cmd=(${(z)1})
26- title $cmd[1]:t "$cmd[2,-1]"
27-}
28-
29 function zsh_stats() {
30 history | awk '{print $2}' | sort | uniq -c | sort -rn | head
31 }
32diff --git a/lib/termsupport.zsh b/lib/termsupport.zsh
33index fef9787486b1d2f5d06ae49958dc0dad73235ff0..e1e536690be580eb0c99a1df47ad5b3df9494073 100644
34--- a/lib/termsupport.zsh
35+++ b/lib/termsupport.zsh
36@@ -1,21 +1,26 @@
37-case "$TERM" in
38- xterm*|rxvt*)
39- preexec () {
40- print -Pn "\e]0;%n@%m: $1\a" # xterm
41- }
42- precmd () {
43- print -Pn "\e]0;%n@%m: %~\a" # xterm
44- }
45- ;;
46- screen*)
47- preexec () {
48- local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]}
49- echo -ne "\ek$CMD\e\\"
50- print -Pn "\e]0;%n@%m: $1\a" # xterm
51- }
52- precmd () {
53- echo -ne "\ekzsh\e\\"
54- print -Pn "\e]0;%n@%m: %~\a" # xterm
55- }
56- ;;
57-esac
58+#usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title
59+#http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
60+#Fully support screen, iterm, and probably most modern xterm and rxvt
61+#Limited support for Apple Terminal (Terminal can't set window or tab separately)
62+function title {
63+ if [[ "$TERM" == "screen" ]]; then
64+ print -Pn "\ek$1\e\\" #set screen hardstatus, usually truncated at 20 chars
65+ elif [[ ($TERM =~ "^xterm") ]] || [[ ($TERM == "rxvt") ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
66+ print -Pn "\e]2;$2\a" #set window name
67+ print -Pn "\e]1;$1\a" #set icon (=tab) name (will override window name on broken terminal)
68+ fi
69+}
70+
71+ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
72+ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
73+
74+#Appears when you have the prompt
75+function precmd {
76+ title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
77+}
78+
79+#Appears at the beginning of (and during) of command execution
80+function preexec {
81+ local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
82+ title "$CMD" "%100>...>$2%<<"
83+}