2015-12-18 10:51:58 -05:00
|
|
|
|
#
|
|
|
|
|
# Minimal theme
|
|
|
|
|
# https://github.com/S1cK94/minimal
|
|
|
|
|
#
|
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
function minimal_user() {
|
|
|
|
|
echo "%(!.$on_color.$off_color)$prompt_char%f"
|
|
|
|
|
}
|
2015-12-18 10:51:58 -05:00
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
function minimal_jobs() {
|
|
|
|
|
echo "%(1j.$on_color.$off_color)$prompt_char%f"
|
|
|
|
|
}
|
2015-12-18 10:51:58 -05:00
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
function minimal_vimode(){
|
|
|
|
|
local ret=""
|
2015-12-18 10:51:58 -05:00
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
case $KEYMAP in
|
|
|
|
|
main|viins)
|
|
|
|
|
ret+="$on_color"
|
|
|
|
|
;;
|
|
|
|
|
vicmd)
|
|
|
|
|
ret+="$off_color"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
2015-12-18 10:51:58 -05:00
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
ret+="$prompt_char%f"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
echo "$ret"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
function minimal_status() {
|
|
|
|
|
echo "%(0?.$on_color.$err_color)$prompt_char%f"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function -prompt_ellipse(){
|
|
|
|
|
local string=$1
|
|
|
|
|
local sep="$rsc..$path_color"
|
|
|
|
|
if [[ $MINIMAL_SHORTEN == true ]] && [[ ${#string} -gt 10 ]]; then
|
|
|
|
|
echo "${string:0:4}$sep${string: -4}"
|
|
|
|
|
else
|
|
|
|
|
echo $string
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
function minimal_path() {
|
|
|
|
|
local path_color="%F{244}"
|
|
|
|
|
local rsc="%f"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
local sep="$rsc/$path_color"
|
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
echo "$path_color$(sed s_/_${sep}_g <<< $(short_pwd))$rsc"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function git_branch_name() {
|
|
|
|
|
local branch_name="$(git rev-parse --abbrev-ref HEAD 2> /dev/null)"
|
|
|
|
|
[[ -n $branch_name ]] && echo "$branch_name"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function git_repo_status(){
|
|
|
|
|
local rs="$(git status --porcelain -b)"
|
|
|
|
|
|
|
|
|
|
if $(echo "$rs" | grep -v '^##' &> /dev/null); then # is dirty
|
2016-01-06 14:06:06 -05:00
|
|
|
|
echo "%F{red}"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
elif $(echo "$rs" | grep '^## .*diverged' &> /dev/null); then # has diverged
|
2016-01-06 14:06:06 -05:00
|
|
|
|
echo "%F{red}"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
elif $(echo "$rs" | grep '^## .*behind' &> /dev/null); then # is behind
|
2016-01-06 14:06:06 -05:00
|
|
|
|
echo "%F{11}"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
elif $(echo "$rs" | grep '^## .*ahead' &> /dev/null); then # is ahead
|
2016-01-06 14:06:06 -05:00
|
|
|
|
echo "%f"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
else # is clean
|
2016-01-06 14:06:06 -05:00
|
|
|
|
echo "%F{green}"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
function minimal_git() {
|
2015-12-18 10:51:58 -05:00
|
|
|
|
local bname=$(git_branch_name)
|
|
|
|
|
if [[ -n $bname ]]; then
|
2016-01-06 14:06:06 -05:00
|
|
|
|
local infos="$(git_repo_status)$bname%f"
|
2015-12-18 10:51:58 -05:00
|
|
|
|
echo " $infos"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function zle-line-init zle-line-finish zle-keymap-select {
|
|
|
|
|
zle reset-prompt
|
|
|
|
|
zle -R
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
function prompt_minimal_precmd() {
|
|
|
|
|
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 10:51:58 -05:00
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
function prompt_minimal_setup() {
|
|
|
|
|
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 10:51:58 -05:00
|
|
|
|
|
2016-01-06 14:06:06 -05:00
|
|
|
|
prompt_minimal_setup "$@"
|