dots/zsh/title
David Majnemer ba2f3cfb85 huge changes and refactoring done:
-   split zsh into many files
-   add bash support
-   cleaned up lots of stuff, created a commonsh folder for common stuff between bash and zsh
-   commonsh supports an order of execution, deliminated by filename. This is to enforce dependencies
All of these changes were needed so that we could sensibly continue to extend the system
2009-01-02 18:37:27 -05:00

71 lines
1.7 KiB
Text
Executable file

# terminal titles
precmd()
{
local termtitle
termtitle=$(print -P "%n@%m")
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 "%(!.-=*[ROOT]*=- | .)%n@%m:")
termtitle=$(print -P "%n@%m:")
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 these two for GNU Screen:
print -nR $'\ek'$1$'\e'"\\"
shift
print -nR $'\e_screen \005 | '$*$'\e'"\\"
;;
xterm*|*rxvt*|cygwin|interix|Eterm|mlterm|kterm|aterm|putty*)
# Use this one instead for everybody else:
shift
print -nR $'\e]0;'$@$'\a'
;;
esac
}