mirror of
https://github.com/hcartiaux/dotfiles.git
synced 2024-10-18 09:15:24 +02:00
[zsh] git prompt file, shfmt run
This commit is contained in:
parent
535522dc91
commit
95e7bad149
1 changed files with 53 additions and 57 deletions
|
@ -1,7 +1,7 @@
|
|||
# hyacinthe prompt theme with git support
|
||||
# Derivated from <http://sebastiancelis.com/2009/11/16/zsh-prompt-git-users/>
|
||||
|
||||
prompt_hyacinthe_help () {
|
||||
prompt_hyacinthe_help() {
|
||||
cat <<'EOF'
|
||||
|
||||
This prompt is color-scheme-able. You can invoke it thus:
|
||||
|
@ -13,7 +13,7 @@ prompt_hyacinthe_help () {
|
|||
EOF
|
||||
}
|
||||
|
||||
prompt_hyacinthe_setup () {
|
||||
prompt_hyacinthe_setup() {
|
||||
|
||||
local p_date p_userpwd p_end p_win
|
||||
local -A pc
|
||||
|
@ -23,7 +23,7 @@ prompt_hyacinthe_setup () {
|
|||
pcc[1]=${1:-${${SSH_CLIENT+'yellow'}:-'red'}}
|
||||
pcc[2]=${2:-'cyan'}
|
||||
|
||||
if [[ "$USERNAME" == "root" ]] ; then
|
||||
if [[ $USERNAME == "root" ]]; then
|
||||
pcc[3]=${3:-'red'}
|
||||
else
|
||||
pcc[3]=${3:-'green'}
|
||||
|
@ -41,7 +41,7 @@ prompt_hyacinthe_setup () {
|
|||
|
||||
p_date="$pc['\[']%F{$pcc[2]}%D{%R}$pc['\]']"
|
||||
|
||||
[[ -n "$WINDOW" ]] && p_win="$pc['\(']%F{$pcc[4]}$WINDOW$pc['\)']"
|
||||
[[ -n $WINDOW ]] && p_win="$pc['\(']%F{$pcc[4]}$WINDOW$pc['\)']"
|
||||
|
||||
p_userpwd="$pc['<']%F{$pcc[3]}%n@%m$p_win%F{$pcc[5]}:%F{$pcc[4]}%~$pc['>']"
|
||||
|
||||
|
@ -51,87 +51,83 @@ prompt_hyacinthe_setup () {
|
|||
prompt="$p_date $p_userpwd $p_end"
|
||||
PS2='%(4_.\.)%3_> %E'
|
||||
|
||||
add-zsh-hook precmd update_git_vars
|
||||
add-zsh-hook precmd update_git_vars
|
||||
add-zsh-hook preexec preexec_update_git_vars
|
||||
add-zsh-hook chpwd update_git_vars
|
||||
add-zsh-hook chpwd update_git_vars
|
||||
}
|
||||
|
||||
update_current_git_vars()
|
||||
{
|
||||
update_current_git_vars() {
|
||||
unset __CURRENT_GIT_BRANCH
|
||||
unset __CURRENT_GIT_BRANCH_STATUS
|
||||
unset __CURRENT_GIT_BRANCH_IS_DIRTY
|
||||
|
||||
local st="$(git status 2>/dev/null)"
|
||||
if [[ -n "$st" ]]; then
|
||||
local -a arr
|
||||
arr=(${(f)st})
|
||||
if [[ -n $st ]]; then
|
||||
local -a arr
|
||||
arr=(${(f)st})
|
||||
|
||||
if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then
|
||||
__CURRENT_GIT_BRANCH='no-branch'
|
||||
else
|
||||
__CURRENT_GIT_BRANCH="${arr[1][(w)4]}";
|
||||
fi
|
||||
if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then
|
||||
__CURRENT_GIT_BRANCH='no-branch'
|
||||
else
|
||||
__CURRENT_GIT_BRANCH="${arr[1][(w)4]}";
|
||||
fi
|
||||
|
||||
if [[ $arr[2] =~ 'Your branch is' ]]; then
|
||||
if [[ $arr[2] =~ 'ahead' ]]; then
|
||||
__CURRENT_GIT_BRANCH_STATUS='ahead'
|
||||
elif [[ $arr[2] =~ 'diverged' ]]; then
|
||||
__CURRENT_GIT_BRANCH_STATUS='diverged'
|
||||
elif [[ $arr[2] =~ 'up-to-date' || $arr[2] =~ 'up to date' ]]; then
|
||||
__CURRENT_GIT_BRANCH_STATUS=''
|
||||
else
|
||||
__CURRENT_GIT_BRANCH_STATUS='behind'
|
||||
fi
|
||||
fi
|
||||
if [[ $arr[2] =~ 'Your branch is' ]]; then
|
||||
if [[ $arr[2] =~ 'ahead' ]]; then
|
||||
__CURRENT_GIT_BRANCH_STATUS='ahead'
|
||||
elif [[ $arr[2] =~ 'diverged' ]]; then
|
||||
__CURRENT_GIT_BRANCH_STATUS='diverged'
|
||||
elif [[ $arr[2] =~ 'up-to-date' || $arr[2] =~ 'up to date' ]]; then
|
||||
__CURRENT_GIT_BRANCH_STATUS=''
|
||||
else
|
||||
__CURRENT_GIT_BRANCH_STATUS='behind'
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ ! $st =~ 'nothing to commit' ]]; then
|
||||
__CURRENT_GIT_BRANCH_IS_DIRTY='1'
|
||||
fi
|
||||
if [[ ! $st =~ 'nothing to commit' ]]; then
|
||||
__CURRENT_GIT_BRANCH_IS_DIRTY='1'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_git_info()
|
||||
{
|
||||
prompt_git_info() {
|
||||
if [ -n "$__CURRENT_GIT_BRANCH" ]; then
|
||||
local s="("
|
||||
case "$__CURRENT_GIT_BRANCH_STATUS" in
|
||||
ahead)
|
||||
s+="↑"
|
||||
;;
|
||||
diverged)
|
||||
s+="↕"
|
||||
;;
|
||||
behind)
|
||||
s+="↓"
|
||||
;;
|
||||
esac
|
||||
if [ -n "$__CURRENT_GIT_BRANCH_IS_DIRTY" ]; then
|
||||
s+="✗"
|
||||
fi
|
||||
s+="$__CURRENT_GIT_BRANCH"
|
||||
s+=")"
|
||||
local s="("
|
||||
case "$__CURRENT_GIT_BRANCH_STATUS" in
|
||||
ahead)
|
||||
s+="↑"
|
||||
;;
|
||||
diverged)
|
||||
s+="↕"
|
||||
;;
|
||||
behind)
|
||||
s+="↓"
|
||||
;;
|
||||
esac
|
||||
if [ -n "$__CURRENT_GIT_BRANCH_IS_DIRTY" ]; then
|
||||
s+="✗"
|
||||
fi
|
||||
s+="$__CURRENT_GIT_BRANCH"
|
||||
s+=")"
|
||||
|
||||
printf " %s%s" "%{${fg[yellow]}%}" $s
|
||||
printf " %s%s" "%{${fg[yellow]}%}" $s
|
||||
fi
|
||||
}
|
||||
|
||||
preexec_update_git_vars()
|
||||
{
|
||||
preexec_update_git_vars() {
|
||||
case "$1" in
|
||||
git*)
|
||||
__EXECUTED_GIT_COMMAND=1
|
||||
;;
|
||||
git*)
|
||||
__EXECUTED_GIT_COMMAND=1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
update_git_vars() {
|
||||
update_current_git_vars
|
||||
|
||||
if [ "$__CURRENT_GIT_BRANCH" != "no-branch" ] ; then
|
||||
if [ "$__CURRENT_GIT_BRANCH" != "no-branch" ]; then
|
||||
RPROMPT="%F{$pcc[3]}$(prompt_git_info)"
|
||||
fi
|
||||
}
|
||||
|
||||
prompt_hyacinthe_setup "$@"
|
||||
|
||||
|
|
Loading…
Reference in a new issue