dots/zsh/title
2012-02-15 01:23:29 -06:00

79 lines
1.8 KiB
Text
Executable file

# terminal titles
precmd()
{
updateprompt
local termtitle
termtitle=`print -P "%n@%m[%l]"`
title zsh "$termtitle"
}
preexec()
{
# With bits from http://zshwiki.org/home/examples/hardstatus
# emulate -L zsh
local -a cmd; cmd=(${(z)1}) # Re-parse the command line
local termtitle
# Prepend this string to the title.
termtitle=`print -P "%n@%m[%l]:"`
case $cmd[1] in
fg)
if (( $#cmd == 1 )); then
# No arguments, must find the current job
# Old approach: cmd=(builtin jobs -l %+)
# weakness: shows a load of bs
title ${jobtexts[${(k)jobstates[(R)*+*]}]%% *} "$termtitle ${jobtexts[${(k)jobstates[(R)*+*]}]}"
elif (( $#cmd == 2 )); then
# Replace the command name, ignore extra args.
# Old approach: cmd=(builtin jobs -l ${(Q)cmd[2]})
# weakness: shows all matching jobs on the title, not just one
title "${jobtexts[${cmd[2]#%}]%% *}" "$termtitle $jobtexts[${cmd[2]#%}]"
else
title "${cmd[2,-1]#%}" "$termtitle ${cmd[2,-1]#%}"
fi
;;
%*)
title "${jobtexts[${cmd[1]#%}]% *}" "$termtitle $jobtexts[${cmd[1]#%}]"
;;
*=*)
shift cmd
;&
exec|sudo)
shift cmd
# If the command is 'exec', drop that, because
# we'd rather just see the command that is being
# exec'd. Note the ;& to fall through the next entry.
;&
*)
title $cmd[1]:t "$termtitle $cmd[*]" # Starting a new job.
;;
esac
}
function title
{
case $TERM in
screen*)
# Use this for GNU Screen:
print -nR $'\ek'$2$'\e'"\\"
;;
interix)
# Use this for interix as "2" makes it upset
shift
print -nR $'\e]0;'$@$'\a'
;;
xterm*|*rxvt*|cygwin|Eterm|mlterm|kterm|aterm|putty*)
if [ "${STY}" ] ; then
print -nR $'\ek'$2$'\e'"\\"
else
# Use this one instead for everybody else:
shift
print -nR $'\e]1;'$@$'\a'
print -nR $'\e]2;'$@$'\a'
fi
;;
esac
}