[clug] Command of the Hour

Nemo clug at nemo.house.cx
Fri Nov 7 14:40:36 GMT 2008

On Thu, Nov 06, 2008 at 04:43:18PM +1100, Alex Satrapa did utter:
> If I open up an xterm, it changes the prompt so that I get two lines  
> like this:
> >[alex at Lancelot:~/Documents/src]
> >16:22 [0|2367]%

I've always been fascinated by prompts - I think because in a text-mode
UI, they're such a big part of that UI... (and I always find UIs

Here is my prompt...

PS1=$'%(?.%{\e[0;36m%}.%{\e[1;31m%}%?)^ %{\e[0m%}%m%4(~.%{\e[0;34m%}.%{\e[0m%}):%{\e[0;34m%}%3~ %{\e[0;32m%}%(!.#.$) %{\e[0m%}'

That gives me a coloured exit status, host:/path in semi*-nfs-friendly
familiar format

* semi- here only because if the path has more than three elements, it
gets truncated to the last three. the ":" delimiter changes colour to
indicate this truncation

Then I also have a right-aligned prompt:

RPS1=$' $(loadavg=`cut -f1 -d" " /proc/loadavg`;([[ $loadavg -lt 0.3 ]] && print "%{\e[0m%}") || ([[ ($loadavg -ge 0.3) && ($loadavg -lt 0.6) ]] && print "%{\e[1m%}") || ([[ ($loadavg -ge 0.6) && ($loadavg -lt 1.0) ]] && print "%{\e[1;33m%}") || print "%{\e[1;31m%}")< %T %{\e[0;33m%}%l%{\e[0m%}'

All that gives me the time and tty, with the time changing colour
according to load. 

The path in PS1 and tty in RPS1 are coloured as expected by anyone
familiar with DIRCOLOURS

> but also changes the xterm title to become:
> >alex at Lancelot: ~/Documents/src
> Then if I run a command such as "vi ~/.zshrc" the title becomes:
> >alex at Lancelot:~/Documents/src - vi ~/.zshrc
> The nifty thing about this is that in Terminal my "Window" menu will  
> contain a list of shells each showing what I was working on at the time.

That is very awesome. I will be stealing ;)

> Thanks to Matthew Hawkins for these tips (10 years ago)!

I got alot of my ZSH-fu from him many years ago too I think :)


  ------------------------------------------ --------------------------
                                                    earth native

More information about the linux mailing list