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.
2 # Fancy setting of the xterm title
4 # Copyright © 1994–2017 martin f. krafft <madduck@madduck.net>
5 # Released under the terms of the Artistic Licence 2.0
7 # Source repository: http://git.madduck.net/v/etc/zsh.git
9 # Based on http://www.zshwiki.org/cgi-bin/wiki.pl?ZshHardStatus
12 autoload -U add-zsh-hook
18 print -nR $'\033k'$1$'\033'\\
19 print -nR $'\033]0;'$2$'\a'
22 print -nR $'\033]0;'$*$'\a'
27 __get_session_flags() {
29 [ -n "$SSH_CONNECTION" ] || return
31 [ -n "$DISPLAY" ] && flags+=x
32 [ -n "$SSH_AUTH_SOCK" ] && flags+=a
33 [[ $SSH_CLIENT = *:* ]] && flags+=6
34 [ -n "$flags" ] && echo "[${flags}]"
37 __get_standard_prompt() {
39 [[ -z $SSH_CLIENT ]] || print -nP "%m"
40 print -P "%#%25\<..\<%~ $(__get_session_flags)"
43 _set_plain_xterm_title() {
45 __set_xterm_title "$(__get_standard_prompt)"
47 add-zsh-hook precmd _set_plain_xterm_title
49 _set_cmd_xterm_title () {
51 local -a cmd; cmd=(${(z)1}) # Re-parse the command line
53 # Construct a command that will output the desired job number.
55 fg) if (( $#cmd == 1 )); then
56 # No arguments, must find the current job
57 cmd=(builtin jobs -l %+)
59 # Replace the command name, ignore extra args.
60 cmd=(builtin jobs -l ${(Q)cmd[2]})
62 %*) cmd=(builtin jobs -l ${(Q)cmd[1]});; # Same as "else" above
63 *) # Not resuming a job,
64 __set_xterm_title $cmd[1]:t${cmd[2]:+ }$cmd[2,-1] "| $(__get_standard_prompt)"
65 return;; # so we're all done
68 local -A jt; jt=(${(kv)jobtexts}) # Copy jobtexts for subshell
70 # Run the command, read its output, and look up the jobtext.
71 # Could parse $rest here, but $jobtexts (via $jt) is easier.
72 $cmd 2>/dev/null >>(read num rest; cmd=(${(z)${(e):-\$jt$num}};)
73 __set_xterm_title $leader$cmd[1]:t${cmd[2]:+ }$cmd[2,-1] "| $(__get_standard_prompt)"
76 add-zsh-hook preexec _set_cmd_xterm_title