Do precmd setup in separate functions

- Use $precmd_functions to call a set of functions prior to each prompt
- Write a separator before each prompt made up of a line of hyphens and a
  right-justified timestamp
This commit is contained in:
Eryn Wells 2011-09-16 11:28:09 -07:00
parent 021b4aa2e2
commit 0bd49aaa56

32
zshrc
View file

@ -29,15 +29,27 @@ else
#mytime="%T" #mytime="%T"
fi fi
PROMPT=" %(?.%h.%B%F{red}%h%F{default}%b) %* %(!.%B%F{red}.)%3~ %#%(!.%F{default}%b.) " PROMPT=" %(?.%h.%B%F{red}%h%F{default}%b) %m %(!.%B%F{red}.)%3~ %#%(!.%F{default}%b.) "
RPROMPT="%m" #RPROMPT="%m"
precmd ()
precmd_xterm_title ()
{ {
# Set xterm and screen titles # Set xterm and screen titles
[ -n $DISPLAY ] && print -Pn "\e]2;%n@%m\a" [ -n $DISPLAY ] && print -Pn "\e]2;%n@%m\a"
} }
precmd_separator ()
{
# time divider
local fillnum=$(($COLUMNS - 9))
local sep=''
for (( i=0; $i < $fillnum; i++)); do sep="-$sep"; done
print -P "%B%F{black}$sep %*%F{default}%b"
}
precmd_functions=(precmd_xterm_title precmd_separator)
# Shell options # Shell options
setopt \ setopt \
TRANSIENT_RPROMPT \ TRANSIENT_RPROMPT \
@ -139,3 +151,17 @@ function up {
pushd ${(j./.)updirs} pushd ${(j./.)updirs}
fi fi
} }
# Toggle showing a separator before every command
function tsep {
if (($precmd_functions[(Ie)precmd_separator] > 0)); then
precmd_functions=${precmd_functions#precmd_separator}
PROMPT=${PROMPT:s/%m/%*/}
RPROMPT="%m"
else
precmd_functions+=(precmd_separator)
PROMPT=${PROMPT:s/%\*/%m/}
unset RPROMPT
fi
}