2015-12-18 16:51:58 +01:00
|
|
|
|
#
|
|
|
|
|
# Minimal theme
|
|
|
|
|
# https://github.com/S1cK94/minimal
|
|
|
|
|
#
|
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
minimal_user() {
|
|
|
|
|
print "%(!.$on_color.$off_color)$prompt_char%f"
|
2016-01-06 20:06:06 +01:00
|
|
|
|
}
|
2015-12-18 16:51:58 +01:00
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
minimal_jobs() {
|
|
|
|
|
print "%(1j.$on_color.$off_color)$prompt_char%f"
|
2016-01-06 20:06:06 +01:00
|
|
|
|
}
|
2015-12-18 16:51:58 +01:00
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
minimal_vimode(){
|
2016-01-06 20:06:06 +01:00
|
|
|
|
local ret=""
|
2015-12-18 16:51:58 +01:00
|
|
|
|
|
2016-01-06 20:06:06 +01:00
|
|
|
|
case $KEYMAP in
|
|
|
|
|
main|viins)
|
|
|
|
|
ret+="$on_color"
|
|
|
|
|
;;
|
|
|
|
|
vicmd)
|
|
|
|
|
ret+="$off_color"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2015-12-18 16:51:58 +01:00
|
|
|
|
|
2016-01-06 20:06:06 +01:00
|
|
|
|
ret+="$prompt_char%f"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
print "$ret"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
minimal_status() {
|
|
|
|
|
print "%(0?.$on_color.$err_color)$prompt_char%f"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
minimal_path() {
|
2016-01-06 20:06:06 +01:00
|
|
|
|
local path_color="%F{244}"
|
|
|
|
|
local rsc="%f"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
local sep="$rsc/$path_color"
|
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
print "$path_color$(sed s_/_${sep}_g <<< $(short_pwd))$rsc"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
git_branch_name() {
|
2016-02-04 21:08:22 +01:00
|
|
|
|
local branch_name="$(command git rev-parse --abbrev-ref HEAD 2> /dev/null)"
|
2016-01-07 14:06:52 +01:00
|
|
|
|
[[ -n $branch_name ]] && print "$branch_name"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
git_repo_status(){
|
2016-02-04 21:08:22 +01:00
|
|
|
|
local rs="$(command git status --porcelain -b)"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
if $(print "$rs" | grep -v '^##' &> /dev/null); then # is dirty
|
|
|
|
|
print "%F{red}"
|
|
|
|
|
elif $(print "$rs" | grep '^## .*diverged' &> /dev/null); then # has diverged
|
|
|
|
|
print "%F{red}"
|
|
|
|
|
elif $(print "$rs" | grep '^## .*behind' &> /dev/null); then # is behind
|
|
|
|
|
print "%F{11}"
|
|
|
|
|
elif $(print "$rs" | grep '^## .*ahead' &> /dev/null); then # is ahead
|
|
|
|
|
print "%f"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
else # is clean
|
2016-01-07 14:06:52 +01:00
|
|
|
|
print "%F{green}"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
minimal_git() {
|
2015-12-18 16:51:58 +01:00
|
|
|
|
local bname=$(git_branch_name)
|
2016-01-07 14:06:52 +01:00
|
|
|
|
if [[ -n ${bname} ]]; then
|
|
|
|
|
local infos="$(git_repo_status)${bname}%f"
|
|
|
|
|
print " $infos"
|
2015-12-18 16:51:58 +01:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function zle-line-init zle-line-finish zle-keymap-select {
|
|
|
|
|
zle reset-prompt
|
|
|
|
|
zle -R
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
prompt_minimal_precmd() {
|
2016-01-06 20:06:06 +01:00
|
|
|
|
zle -N zle-line-init
|
|
|
|
|
zle -N zle-keymap-select
|
|
|
|
|
zle -N zle-line-finish
|
|
|
|
|
|
|
|
|
|
PROMPT='$(minimal_user)$(minimal_jobs)$(minimal_vimode)$(minimal_status) '
|
|
|
|
|
RPROMPT='$(minimal_path)$(minimal_git)'
|
|
|
|
|
}
|
2015-12-18 16:51:58 +01:00
|
|
|
|
|
2016-01-07 14:06:52 +01:00
|
|
|
|
prompt_minimal_setup() {
|
2016-01-06 20:06:06 +01:00
|
|
|
|
prompt_char="❯"
|
|
|
|
|
on_color="%F{green}"
|
|
|
|
|
off_color="%f"
|
|
|
|
|
err_color="%F{red}"
|
|
|
|
|
|
|
|
|
|
autoload -Uz add-zsh-hook
|
|
|
|
|
|
|
|
|
|
add-zsh-hook precmd prompt_minimal_precmd
|
|
|
|
|
prompt_opts=(cr subst percent)
|
|
|
|
|
}
|
2015-12-18 16:51:58 +01:00
|
|
|
|
|
2016-01-06 20:06:06 +01:00
|
|
|
|
prompt_minimal_setup "$@"
|