Useful macros for zsh

I’m a zsh fiend. I’ve been using it as my shell of choice since about ‘97. compctl is absolutely wonderful, and it’s bourne compatibility is nearly second to none, without being quite as antsy as bash2.

That said, today I’ve opted to share a few macros from my .zshrc

rfc () { curl -s http://www.ietf.org/rfc/rfc$1.txt | less }
qdb () { lynx http://bash.org/\?$1 }
imdb () { lynx http://uk.imdb.com/Title\?$1 }
reni () { sudo renice -20 `ps -axww | grep -i -e $1 | awk ’{ print $1}’ | \ grep -v grep | grep -v ps | sort -b -n -r | head -1` }

The above will query an rfc, download, and display it, read a quote number you specify from bash.org, and do an imdb request based upon an entry. The last is a rather icky setup; hardly optimal, but compatible with ever UNIX variant I’ve used, to renice a priority -20 to give it a bit more CPU leeway, it takes a process name, and will renice the very last PID of the given account. This is written to only work for your current $USER, so you don’t accidently renice someone else’s process. This works rather well on my slow laptop to give MPlayer a bit of a needed boost when watching movies and whatnot. It’s case insensitive, so ‘reni mplayer’ should work fine.

I usually use an XTerm compatible application, or GLTerm locally, and as such, I like to know what I’m doing, and indeed, what machine I’m on.

I’ve got the following set with zsh’s spiffydoodle pre/postcmd:

if [ “x$TERM” = “xscreen” ] && [ “x$TERM” != “xlinux” ]
then precmd () {print -Pn ”\e]0;%n@%m\a”} preexec () { print -Pn ”\e]0;\”$*[0]\” @%m\a” }
fi

The above will change the status bar to print what, and where I am executing, then set the prompt back to normal once the application exits. Note that this is not unfallable, it needs to be setup for every .zshrc on every host, of course, and the above only falls out if it detects a standard FreeBSD or Linux console. As well, there’s no real trivial way of remembering the prior application if you break out, then bring it back to the foreground, so it will display ‘fg’, or whatnot (as seen below). Feel free to adapt to your needs. ;)