use builtin fish git prompt
This commit is contained in:
parent
b5dcb4da56
commit
51753ef894
2 changed files with 5 additions and 60 deletions
|
@ -62,3 +62,7 @@ source ~/.config/fish/command_timer.sh
|
||||||
# Removes greeting message
|
# Removes greeting message
|
||||||
set fish_greeting
|
set fish_greeting
|
||||||
|
|
||||||
|
set -g __fish_git_prompt_show_informative_status 1
|
||||||
|
set -g __fish_git_prompt_shorten_branch_len 20
|
||||||
|
set -g __fish_git_prompt_showcolorhints 1
|
||||||
|
|
||||||
|
|
|
@ -17,65 +17,6 @@ function __bcarlin_prompt_suffix
|
||||||
echo -n -s ' ' (set_color $color_suffix --bold) "$suffix" (set_color normal) ' '
|
echo -n -s ' ' (set_color $color_suffix --bold) "$suffix" (set_color normal) ' '
|
||||||
end
|
end
|
||||||
|
|
||||||
function __bcarlin_prompt_git
|
|
||||||
set -l git_infos (git status --porcelain --branch ^/dev/null )
|
|
||||||
if test $status -ne 0
|
|
||||||
echo -n -s ''
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
set -l git_branch (echo $git_infos | grep '##' | sed -e 's/## \([a-zA-Z0-9\/-]\+\)\( \|\.\.\.\|$\).*/\1/')
|
|
||||||
set -l has_untracked false
|
|
||||||
set -l staged_count 0
|
|
||||||
set -l changed_count 0
|
|
||||||
set -l conflict_count 0
|
|
||||||
set -l staged_count 0
|
|
||||||
set -l behind (echo $git_infos | grep '##' | grep behind | sed -e 's|.*behind \([0-9]\+\).*|\1|')
|
|
||||||
set -l ahead (echo $git_infos | grep '##' | grep ahead | sed -e 's|.*ahead \([0-9]\+\).*|\1|')
|
|
||||||
|
|
||||||
for line in $git_infos
|
|
||||||
set -l flags (echo $line | cut -c '-2')
|
|
||||||
set flag1 (string sub -l 1 $flags)
|
|
||||||
set flag2 (string sub -s 2 -l 1 $flags)
|
|
||||||
|
|
||||||
if test $flags = '??'
|
|
||||||
set has_untracked true
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
|
|
||||||
if test $flag1 = 'U' -o $flag2 = 'U'
|
|
||||||
set conflict_count (math $conflict_count + 1)
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
|
|
||||||
if contains $flag1 'M' 'A' 'C' 'R' 'D'
|
|
||||||
set staged_count (math $staged_count + 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
if contains $flag2 'M' 'A' 'R' 'C' 'D'
|
|
||||||
set changed_count (math $changed_count + 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
echo -n -s ' ' (set_color blue) ± (set_color normal) '('
|
|
||||||
echo -n -s (set_color red --bold) $git_branch (set_color normal)
|
|
||||||
|
|
||||||
if test (math $staged_count + $conflict_count + $changed_count) -ne 0 -o $has_untracked = true
|
|
||||||
echo -n -s '|'
|
|
||||||
test -n "$behind"; and echo -s -n (set_color red) "↓$behind" (set_color normal)
|
|
||||||
test -n "$ahead"; and echo -s -n (set_color green) "↑$ahead" (set_color normal)
|
|
||||||
test $conflict_count -ne 0; and echo -s -n (set_color red) "✖$conflict_count" (set_color normal)
|
|
||||||
test $staged_count -ne 0; and echo -s -n (set_color red) "●$staged_count" (set_color normal)
|
|
||||||
test $changed_count -ne 0; and echo -s -n (set_color blue) "✚$changed_count" (set_color normal)
|
|
||||||
test $has_untracked = true; and echo -s -n '…'
|
|
||||||
else
|
|
||||||
echo -n -s (set_color green --bold) "✔" (set_color normal)
|
|
||||||
end
|
|
||||||
|
|
||||||
echo -n -s ')'
|
|
||||||
end
|
|
||||||
|
|
||||||
function __bcarlin_prompt_venv
|
function __bcarlin_prompt_venv
|
||||||
if test -n "$VIRTUAL_ENV"
|
if test -n "$VIRTUAL_ENV"
|
||||||
set -l venv_name (basename $VIRTUAL_ENV)
|
set -l venv_name (basename $VIRTUAL_ENV)
|
||||||
|
@ -92,7 +33,7 @@ function fish_prompt --description 'Write out the prompt'
|
||||||
|
|
||||||
echo -n -s (__bcarlin_prompt_venv)
|
echo -n -s (__bcarlin_prompt_venv)
|
||||||
echo -n -s "$USER" @ (prompt_hostname) ' ' $_pwd
|
echo -n -s "$USER" @ (prompt_hostname) ' ' $_pwd
|
||||||
echo -n -s (__bcarlin_prompt_git)
|
echo -n -s (__fish_git_prompt)
|
||||||
if test $last_status -ne 0
|
if test $last_status -ne 0
|
||||||
echo -n -s (set_color red --bold)" [$last_status]" (set_color normal)
|
echo -n -s (set_color red --bold)" [$last_status]" (set_color normal)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue