Commit b14e7101 authored by Joseph Tannhuber's avatar Joseph Tannhuber

Git right prompt implemented

parent 3567690e
# TODO: color definitions # TODO: color definitions
# TODO: elapsed time segment # TODO: elapsed time segment
# TODO: configurable pwd_style
function __budspencer_is_git_ahead -d "Check if there are unpushed commits" function __budspencer_is_git_ahead_or_behind -d "Check if there are unpulled or unpushed commits"
echo (command git status -s -b ^/dev/null | grep ahead) echo (command git rev-list --count --left-right "HEAD...@{upstream}" ^/dev/null | sed 's/[[:space:]+]/\\x1e/g')
end end
function __budspencer_is_git_behind -d "Check if there are unpushed commits" function __budspencer_git_status -d "Check git status"
echo (command git status -s -b ^/dev/null | grep behind) set -l added 0
end set -l deleted 0
set -l modified 0
function __budspencer_is_git_added -d "Check if there are added files" set -l renamed 0
echo (command git status -s -b ^/dev/null | grep "^A") set -l unmerged 0
end set -l untracked 0
set -l git_status (command git status --porcelain ^/dev/null)
function __budspencer_is_git_deleted -d "Check if there are deleted files" for i in (seq 1 (count $git_status))
echo (command git status -s -b ^/dev/null | grep "^.D") echo $git_status[$i] | egrep "^[ACDMT][\ MT]\ |^[ACMT]D\ " > /dev/null; and set added (math $added+1)
end echo $git_status[$i] | egrep "^[\ ACMRT]D\ " > /dev/null; and set deleted (math $deleted+1)
echo $git_status[$i] | egrep "^.[MT]\ " > /dev/null; and set modified (math $modified+1)
function __budspencer_is_git_changed -d "Check if there are changed files" echo $git_status[$i] | egrep "^R.\ " > /dev/null; and set renamed (math $renamed+1)
echo (command git status -s -b ^/dev/null | grep "^.M") echo $git_status[$i] | egrep "^AA\ |^DD\ |^U.\ |^.U\ " > /dev/null; and set unmerged (math $unmerged+1)
end echo $git_status[$i] | egrep "^\?\?\ " > /dev/null; and set untracked (math $untracked+1)
end
function __budspencer_is_git_uncomitted -d "Check if there are uncommited changes" printf '%s\x1e%s\x1e%s\x1e%s\x1e%s\x1e%s' $added $deleted $modified $renamed $unmerged $untracked
echo (command git status -s -b ^/dev/null | grep "^??")
end end
function __budspencer_is_git_stashed -d "Check if there are stashed commits" function __budspencer_is_git_stashed -d "Check if there are stashed commits"
echo (command git stash list ^/dev/null) echo (command git stash list ^/dev/null | wc -l | awk '{print $1}')
end end
if set -q -x $PWDSTYLE if set -q -x $PWDSTYLE
...@@ -116,33 +114,47 @@ function fish_right_prompt -d "Write out the right prompt of the budspencer them ...@@ -116,33 +114,47 @@ function fish_right_prompt -d "Write out the right prompt of the budspencer them
# git # git
set -l ps_git "" set -l ps_git ""
if test -n (__budspencer_is_git_ahead) set -l is_repo (command git rev-parse --is-inside-work-tree ^/dev/null)
if test $is_repo="true"
set -l git_ahead_behind (__budspencer_is_git_ahead_or_behind)
if test $git_ahead_behind[1] -gt 0
set ps_git $fcol_yellow" ↑" set ps_git $fcol_yellow" ↑"
end end
if test -n (__budspencer_is_git_behind) if test $git_ahead_behind[2] -gt 0
set ps_git $ps_git$fcol_yellow" ↓" set ps_git $ps_git$fcol_yellow" ↓"
end end
if test -n (__budspencer_is_git_added) set -l git_status (__budspencer_git_status)
echo $git_status
if test $git_status[1] -gt 0
set ps_git $ps_git$fcol_green" +" set ps_git $ps_git$fcol_green" +"
end end
if test -n (__budspencer_is_git_deleted) if test $git_status[2] -gt 0
set ps_git $ps_git$fcol_red" –" set ps_git $ps_git$fcol_red" –"
end end
if test -n (__budspencer_is_git_changed) if test $git_status[3] -gt 0
set ps_git $ps_git$fcol_blue" ✱" set ps_git $ps_git$fcol_blue" ✱"
end end
if test -n (__budspencer_is_git_uncomitted) if test $git_status[4] -gt 0
set ps_git $ps_git$fcol_blue" →"
end
if test $git_status[5] -gt 0
set ps_git $ps_git$fcol_violet" ═"
end
if test $git_status[6] -gt 0
set ps_git $ps_git$fcol_base3" ●" set ps_git $ps_git$fcol_base3" ●"
end end
if test -n (__budspencer_is_git_stashed) if test (__budspencer_is_git_stashed) -gt 0
set ps_git $ps_git$fcol_cyan" ✭" set ps_git $ps_git$fcol_cyan" ✭"
end end
end
if test -n "$ps_git" if test -n "$ps_git"
set ps_git $fcol_base02""$bcol_base02""$ps_git set ps_git $fcol_base02""$bcol_base02""$ps_git
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment