1
0
Fork 0
mirror of synced 2024-11-16 13:05:35 -05:00
zimfw/modules/prompt/themes/minimal.zsh-theme
caedus75 f2806b45bf fix prompt substitutions/expansions
The 'prompt' function disables any option set with 'setopt'.
To make options persistent we need to use the 'prompt_opts' array
instead

Closes #8
2015-12-30 04:42:31 -05:00

103 lines
2.2 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#
# Minimal theme
# https://github.com/S1cK94/minimal
#
autoload -Uz colors && colors
prompt_opts=( cr subst percent )
PROMPT_CHAR=""
ON_COLOR="%{$fg[green]%}"
OFF_COLOR="%{$reset_color%}"
ERR_COLOR="%{$fg[red]%}"
function prompt_user() {
echo "%(!.$ON_COLOR.$OFF_COLOR)$PROMPT_CHAR%{$reset_color%}"
}
function prompt_jobs() {
echo "%(1j.$ON_COLOR.$OFF_COLOR)$PROMPT_CHAR%{$reset_color%}"
}
function prompt_status() {
echo "%(0?.$ON_COLOR.$ERR_COLOR)$PROMPT_CHAR%{$reset_color%}"
}
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
}
function prompt_path() {
local path_color="%{%}%}"
local rsc="%{$reset_color%}"
local sep="$rsc/$path_color"
echo "$path_color$(print -P %2~ | sed s_/_${sep}_g)$rsc"
}
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
echo "%{$fg[red]%}"
elif $(echo "$rs" | grep '^## .*diverged' &> /dev/null); then # has diverged
echo "%{$fg[red]%}"
elif $(echo "$rs" | grep '^## .*behind' &> /dev/null); then # is behind
echo "%{%}%}"
elif $(echo "$rs" | grep '^## .*ahead' &> /dev/null); then # is ahead
echo "%{$reset_color%}"
else # is clean
echo "%{$fg[green]%}"
fi
}
function prompt_git() {
local bname=$(git_branch_name)
if [[ -n $bname ]]; then
local infos="$(git_repo_status)$bname%{$reset_color%}"
echo " $infos"
fi
}
function prompt_vimode(){
local ret=""
case $KEYMAP in
main|viins)
ret+="$ON_COLOR"
;;
vicmd)
ret+="$OFF_COLOR"
;;
esac
ret+="$PROMPT_CHAR%{$reset_color%}"
echo "$ret"
}
function zle-line-init zle-line-finish zle-keymap-select {
zle reset-prompt
zle -R
}
zle -N zle-line-init
zle -N zle-keymap-select
zle -N zle-line-finish
PROMPT='$(prompt_user)$(prompt_jobs)$(prompt_vimode)$(prompt_status) '
RPROMPT='$(prompt_path)$(prompt_git)'