]> git.madduck.net Git - etc/zsh.git/blob - .zsh/zshrc/80_xtermtitle

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

show todo items on entry to dir
[etc/zsh.git] / .zsh / zshrc / 80_xtermtitle
1 # zshrc/80_xtermtitle
2 #
3 # Fancy setting of the xterm title
4 #
5 # Copyright © 1994–2008 martin f. krafft <madduck@madduck.net>
6 # Released under the terms of the Artistic Licence 2.0
7 #
8 # Source repository: http://git.madduck.net/v/etc/zsh.git
9 #
10 # Based on http://www.zshwiki.org/cgi-bin/wiki.pl?ZshHardStatus
11 #
12
13 __set_xterm_title() {
14   case $TERM in
15     screen)
16       print -nR $'\033k'$1$'\033'\\ 
17       print -nR $'\033]0;'$2$'\a'
18       ;;
19     xterm|rxvt*)
20       print -nR $'\033]0;'$*$'\a'
21       ;;
22   esac
23 }
24
25 __get_session_flags() {
26   [ -n "$SSH_CONNECTION" ] || return
27   local flags; flags=
28   [ -n "$DISPLAY" ] && flags="${flags}x"
29   [ -n "$SSH_AUTH_SOCK" ] && flags="${flags}a"
30   [[ $SSH_CLIENT = *:* ]] && flags="${flags}6"
31   [ -n "$flags" ] && echo "[${flags}]"
32 }
33
34 __get_standard_prompt() {
35   print -P "%m%#%25\<..\<%~ $(__get_session_flags)"
36 }
37
38 _set_plain_xterm_title() {
39   __set_xterm_title "$(__get_standard_prompt)"
40 }
41 precmd_functions+=_set_plain_xterm_title
42
43 _set_cmd_xterm_title () {
44     local -a cmd; cmd=(${(z)1})             # Re-parse the command line
45
46     # Construct a command that will output the desired job number.
47     case $cmd[1] in
48         fg) if (( $#cmd == 1 )); then
49                 # No arguments, must find the current job
50                 cmd=(builtin jobs -l %+)
51             else
52                 # Replace the command name, ignore extra args.
53                 cmd=(builtin jobs -l ${(Q)cmd[2]})
54             fi;;
55         %*) cmd=(builtin jobs -l ${(Q)cmd[1]});; # Same as "else" above
56         *) # Not resuming a job,
57             __set_xterm_title $cmd[1]:t${cmd[2]:+ }$cmd[2,-1] "| $(__get_standard_prompt)"
58             return;;                        # so we're all done
59     esac
60
61     local -A jt; jt=(${(kv)jobtexts})       # Copy jobtexts for subshell
62
63     # Run the command, read its output, and look up the jobtext.
64     # Could parse $rest here, but $jobtexts (via $jt) is easier.
65     $cmd >>(
66               read num rest
67               cmd=(${(z)${(e):-\$jt$num}})
68               __set_xterm_title $leader$cmd[1]:t${cmd[2]:+ }$cmd[2,-1] "| $(__get_standard_prompt)"
69            )
70 }
71 preexec_functions+=_set_cmd_xterm_title
72
73 # vim:ft=zsh