Created
April 5, 2013 22:01
-
-
Save mythmon/5322997 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
autoload promptinit | |
promptinit | |
setopt prompt_subst | |
autoload -Uz vcs_info | |
if vcs_info 2> /dev/null; then | |
zstyle ':vcs_info:*' enable git | |
zstyle ':vcs_info:git*:*' get-revision true | |
zstyle ':vcs_info:git*:*' check-for-changes true | |
zstyle ':vcs_info:*' actionformats "%s%c%u %r/%S:%F{7}%b%F{85}#%0.6i%f:%a" | |
zstyle ':vcs_info:*' formats "%s%c%u %r/%S:%F{7}%b%F{85}#%0.6i%f" | |
fi | |
# Called right before a command runs | |
preexec_prompt () { | |
resetpromptcount="0" | |
# post-command prompt gets a long time and a short tty | |
pstime=" %F{cyan}%*%f" # for post-command prompt | |
psstarttime=$(date +%s) | |
lasttime="" | |
ODIR="$(pwd)" | |
} | |
add-zsh-hook preexec preexec_prompt | |
# Called right before drawing a prompt. | |
precmd_prompt () { | |
lastexit=$? | |
pstime="%F{brgreen}%T%f" | |
pspath="%F{green}%~%f" | |
pshost="%F{$(hash_color $(hostname))}%m%f" | |
psuser="%n" | |
if [[ $lastexit -eq 0 ]]; then | |
psat="%F{2}@%f" | |
else | |
psat="%F{9}$lastexit@%f" | |
fi | |
# If the last command took longer than some time to run, say so. | |
if [ -n "$psstarttime" ] ; then | |
exectimeraw=$(($(date +%s)-$psstarttime)) | |
if [ $exectimeraw -gt 30 ] ; then | |
if [ $exectimeraw -lt 100 ] ; then | |
lasttime="${exectimeraw}s" | |
else | |
execmin=$(($exectimeraw/60)) | |
execsec=$(($exectimeraw%60)) | |
if [ $execmin -lt 100 ] ; then | |
lasttime="${execmin}m${execsec}s" | |
else | |
exechr=$(($execmin/60)) | |
execmin=$(($execmin%60)) | |
lasttime="${exechr}h${execmin}m${execsec}s" | |
if [ $exechr -ge 36 ] ; then | |
execday=$(($exechr/24)) | |
exechr=$(($exechr%24)) | |
lasttime="${execday}d${exechr}h${execmin}m" | |
fi | |
fi | |
fi | |
echo "Runtime: $lasttime" | |
fi | |
fi | |
psstarttime="" | |
vcs_info | |
if [[ -n $vcs_info_msg_0_ ]] ; then | |
# Turn foo/bar/. into foo/bar in paths. | |
psvcs=$(echo $vcs_info_msg_0_ | sed -e 's_^\([^/]\+\)/\._\1_') | |
# If branch name is master, hide it. | |
psvcs=$(echo $psvcs | sed -e 's/:%F{[0-9]\+}master//') | |
# Replace VCS name and status with stop light colored logo | |
psvcs=$(echo $psvcs | sed -e 's/gitSU/%F{yellow}±%F{blue}/') | |
psvcs=$(echo $psvcs | sed -e 's/gitS/%F{green}±%F{blue}/') | |
psvcs=$(echo $psvcs | sed -e 's/gitU/%F{red}±%F{blue}/') | |
psvcs=$(echo $psvcs | sed -e 's/git/±/') | |
# turn it blue | |
psvcs="%F{blue}${psvcs}%f" | |
pspath="" | |
else | |
psvcs="" | |
fi | |
if [[ -z $(ssh-add -l) ]]; then | |
keychain=" " | |
else | |
keychain="%F{cyan}⚷%f" | |
fi | |
} | |
add-zsh-hook precmd precmd_prompt | |
TMOUT=20 | |
TRAPALRM () { | |
zle reset-prompt | |
} | |
PROMPT='${psat}${pshost}> ' | |
#RPROMPT='${pspath}${psvcs}${keychain}${pstime}' | |
RPROMPT='${pspath}${psvcs}' | |
#EOF vim: ft=zsh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment