[clug] Command of the Hour
Alex Satrapa
grail at goldweb.com.au
Thu Nov 6 05:43:18 GMT 2008
Not strictly a command, but more hacking with ZSH:
> function settitle
> {
> print -Pn "\e]0;$1\a"
> return 0
> }
>
> function twolineprompt
> {
> # Generate two-line command prompt
> PS1=`echo "%{\\e[$1m[%n@%m:%~]\\e[0m\n\\e[$2m%}%D{%k:%M} [%?|%!]%#
> %{\\e[0m%} "`
> return 0
> }
>
> # I often like using shortprompt '41;37;1'
> function shortprompt
> {
> PS1=`echo "%{\\e[\$1m%}%T [%?|%!]%#%{\\e[0m%} "`
> return 0
> }
>
> function invshort
> {
> shortprompt '41;37;1'
> return 0
> }
>
> unset LSCOLORS
> case "$TERM" in
> nsterm | rxvt | xterm | xterm-color)
> # Use window titlebar to display some information
> settitle "%n@%m: %~"
> # Display the new directory when changing directories
> precmd () { settitle "%n@%m: %5(~:%-1~/.../%3~:%~)" }
> preexec () { settitle "%n@%m :%5(~:%-1~/.../%3~:%~) - $1" }
> twolineprompt '35' '35'
> ;;
> ansi)
> unfunction precmd
> unfunction preexec
> twolineprompt '0;43' '32'
> ;;
> *)
> unfunction precmd
> unfunction preexec
> # Generate safe prompt
> PS1="[%?|%!]-[%n@%m: %~]%# "
> ;;
> esac
What does this achieve?
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]%
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.
Thanks to Matthew Hawkins for these tips (10 years ago)!
Alex
More information about the linux
mailing list