Browse code

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)

Renaud (Nel) Morvan authored on 30/01/2011 at 07:21:49
Showing 2 changed files
... ...
@@ -1,26 +1,3 @@
1
-## fixme, i duplicated this in xterms - oops
2
-function title {
3
-  if [[ $TERM == "screen" ]]; then
4
-    # Use these two for GNU Screen:
5
-    print -nR $'\033k'$1$'\033'\\\
6
-
7
-    print -nR $'\033]0;'$2$'\a'
8
-  elif [[ ($TERM =~ "^xterm") ]] || [[ ($TERM == "rxvt") ]]; then
9
-    # Use this one instead for XTerms:
10
-    print -nR $'\033]0;'$*$'\a'
11
-  fi
12
-}
13
-
14
-function precmd {
15
-  title zsh "$PWD"
16
-}
17
-
18
-function preexec {
19
-  emulate -L zsh
20
-  local -a cmd; cmd=(${(z)1})
21
-  title $cmd[1]:t "$cmd[2,-1]"
22
-}
23
-
24 1
 function zsh_stats() {
25 2
   history | awk '{print $2}' | sort | uniq -c | sort -rn | head
26 3
 }
... ...
@@ -1,21 +1,26 @@
1
-case "$TERM" in
2
-  xterm*|rxvt*)
3
-    preexec () {
4
-      print -Pn "\e]0;%n@%m: $1\a"  # xterm
5
-    }
6
-    precmd () {
7
-      print -Pn "\e]0;%n@%m: %~\a"  # xterm
8
-    }
9
-    ;;
10
-  screen*)
11
-    preexec () {
12
-      local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]}
13
-      echo -ne "\ek$CMD\e\\"
14
-      print -Pn "\e]0;%n@%m: $1\a"  # xterm
15
-    }
16
-    precmd () {
17
-      echo -ne "\ekzsh\e\\"
18
-      print -Pn "\e]0;%n@%m: %~\a"  # xterm
19
-    }
20
-    ;;
21
-esac
22 1
\ No newline at end of file
2
+#usage: title short_tab_title looooooooooooooooooooooggggggg_windows_title
3
+#http://www.faqs.org/docs/Linux-mini/Xterm-Title.html#ss3.1
4
+#Fully support screen, iterm, and probably most modern xterm and rxvt
5
+#Limited support for Apple Terminal (Terminal can't set window or tab separately)
6
+function title {
7
+  if [[ "$TERM" == "screen" ]]; then 
8
+    print -Pn "\ek$1\e\\" #set screen hardstatus, usually truncated at 20 chars
9
+  elif [[ ($TERM =~ "^xterm") ]] || [[ ($TERM == "rxvt") ]] || [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then
10
+    print -Pn "\e]2;$2\a" #set window name
11
+    print -Pn "\e]1;$1\a" #set icon (=tab) name (will override window name on broken terminal)
12
+  fi
13
+}
14
+
15
+ZSH_THEME_TERM_TAB_TITLE_IDLE="%15<..<%~%<<" #15 char left truncated PWD
16
+ZSH_THEME_TERM_TITLE_IDLE="%n@%m: %~"
17
+
18
+#Appears when you have the prompt
19
+function precmd {
20
+  title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
21
+}
22
+
23
+#Appears at the beginning of (and during) of command execution
24
+function preexec {
25
+  local CMD=${1[(wr)^(*=*|sudo|ssh|-*)]} #cmd name only, or if this is sudo or ssh, the next cmd
26
+  title "$CMD" "%100>...>$2%<<"
27
+}