Last active
August 26, 2016 07:05
-
-
Save DarkoKukovec/16fb797b907cc3c4d4cf614ae69adab1 to your computer and use it in GitHub Desktop.
This file contains 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
zmodload zsh/regex | |
setopt REMATCH_PCRE | |
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)" | |
parse_node_version() { | |
(command node -v | sed -e 's/v//g') 2>/dev/null; | |
} | |
parse_ruby_version() { | |
(command ruby -e 'puts RUBY_VERSION') 2>/dev/null; | |
} | |
get_exec_time() { | |
if [ $timer ]; then | |
timer_show=$(($(mstime) - $timer)) | |
timer_time="ms" | |
echo "%F{cyan}${timer_show}${timer_time}%{$reset_color%} | " | |
unset timer | |
fi | |
} | |
get_node_version() { | |
echo "%{$fg_bold[green]%}N%{$reset_color%}:$(parse_node_version)%{$reset_color%}" | |
} | |
parse_git_dirty() { | |
if command git diff-index --quiet HEAD 2> /dev/null; then | |
if [[ $(git rev-list @{u}.. 2> /dev/null) ]]; then | |
echo "%{$fg[yellow]%}$(git_custom_status)%{$reset_color%}" | |
else | |
echo "%{$fg[green]%}$(git_custom_status)%{$reset_color%}" | |
fi | |
else | |
echo "%{$fg[red]%}$(git_custom_status)%{$reset_color%}" | |
fi | |
} | |
parse_git_branch() { | |
(command git symbolic-ref -q HEAD || command git name-rev --name-only --no-undefined --always HEAD) 2>/dev/null | |
} | |
git_custom_status() { | |
local git_where="$(parse_git_branch)" | |
[ -n "$git_where" ] && echo "${git_where#(refs/heads/|tags/)}%{$reset_color%} |" | |
} | |
preexec() { | |
timer=$(mstime) | |
} | |
mstime() { | |
gdate +%s%N | cut -b1-13 | |
} | |
# add-time() { | |
# # BUFFER="time $BUFFER"; | |
# # echo $PREBUFFER | |
# # echo $CURSOR | |
# zle .accept-line "$@"; | |
# time $BUFFER | |
# } | |
# zle -N accept-line add-time | |
# TRAPDEBUG() { eval "time $ZSH_DEBUG_CMD"; setopt errexit; } | |
PROMPT='%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}%{$fg_bold[blue]%}% ${ret_status}%{$reset_color%} ' | |
RPROMPT='$(parse_git_dirty) $(get_exec_time)$(get_node_version)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment