.zshrc updates

Sep 30, 2005 00:21

There were two problems with my .zshrc snippet for screen/xterm integration.

1. if you ran a command with a zsh escape in it (like %s), your prompt was clobbered. Fix:

function title() {
[[ -t 1 ]] || return
a=${1//\%/\%\%}
case $TERM in
screen)
print -Pn "\e]2;$a $2\a"
print -Pn "\ek$a\e\\"
print -Pn "\e_$2 \e\\"
;;
xterm*|rxvt)
print -Pn "\e]2;$a - $2\a"
;;
esac
}

2. "fg" would show up as the current process if you're doing stuff with job control, which sucks. zsh and coprocesses to the rescue:

function preexec() {
cmd=${1:t}
set _ $cmd
shift
if [ "$1" = "fg" ]; then
# "fg" isn't useful. see what the job is.
coproc jobs ${2:-%%} 2>/dev/null
_j=$(head -1 <&p)
if [ ! -z "$_j" ]; then
jobnum=$(expr "$_j" : "\[\([0-9][0-9]*\)\].*")
set _ $jobtexts[$jobnum]
cmd=${2:t}
fi
fi
title "$cmd" "%m(%35<...<%~)"
}

I can't believe tomorrow is Friday already.
Previous post Next post
Up