* showing the current job in the window title
@ 2007-08-05 19:33 Dana Jansens
0 siblings, 0 replies; only message in thread
From: Dana Jansens @ 2007-08-05 19:33 UTC (permalink / raw)
To: zsh-users
Hi,
I recently decided I wanted to show the current job I am using in my
xterm window titles. I found, with some help, an example on this
mailing list but it was incomplete and not functional. So I thought I
would share my success with you all, in case other people would be
interested to do the same in the future.
One interesting thing about it is that "builtin jobs %+" (or %1, %2,
etc) does not seem to work at all in preexec(). It would give off
strange errors instead such as "no such job: 1". However using grep I
was able to attain the same result.
preexec () {
local -a cmd
local -a job
if [ $#1 -gt 512 ];then 1=${1[1,512]}; fi
cmd=(${(z)1})
case $cmd[1] in
(fg)
if (( $#cmd == 1 )); then
builtin jobs | grep "^\[[0-9]\+\]\W\++" | read job
job=$job[19,-1]
else
builtin jobs | grep "^\[${(Q)cmd[2][2,-1]}\]" | read job
job=$job[19,-1]
fi ;;
(r)
builtin history -n -1 | read job ;;
(%*)
builtin jobs | grep "^\[${(Q)cmd[1][2,-1]}\]" | read job
job=$job[19,-1] ;;
(exec)
job=($cmd)
shift job ;;
(*)
job=$cmd ;;
esac
ct -e "`print -P "%n@%m"` {$job} [`print -P "%100<...<%~%<<"`]"
}
ct () {
local MATCH
if [[ "$1" = "-e" ]]
then
print -n "\033]0;${(q)${2//
/\\n}//(#m)[-]/$MATCH}\007"
elif [[ "$1" = "-t" ]]
then
pts="$2"
ct -e "$3" > /dev/pts/$pts
else
ct -e "$*"
fi
}
Yay for zsh!
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-08-05 19:40 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-05 19:33 showing the current job in the window title Dana Jansens
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).