2014-06-01 15:39:07 +08:00
|
|
|
set -g fish_color_git_clean green
|
|
|
|
set -g fish_color_git_staged yellow
|
|
|
|
set -g fish_color_git_dirty red
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2014-06-01 15:39:07 +08:00
|
|
|
set -g fish_color_git_added green
|
|
|
|
set -g fish_color_git_modified blue
|
|
|
|
set -g fish_color_git_renamed magenta
|
|
|
|
set -g fish_color_git_copied magenta
|
|
|
|
set -g fish_color_git_deleted red
|
|
|
|
set -g fish_color_git_untracked yellow
|
|
|
|
set -g fish_color_git_unmerged red
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2014-06-01 15:39:07 +08:00
|
|
|
set -g fish_prompt_git_status_added '✚'
|
|
|
|
set -g fish_prompt_git_status_modified '*'
|
|
|
|
set -g fish_prompt_git_status_renamed '➜'
|
|
|
|
set -g fish_prompt_git_status_copied '⇒'
|
|
|
|
set -g fish_prompt_git_status_deleted '✖'
|
|
|
|
set -g fish_prompt_git_status_untracked '?'
|
2019-05-05 18:09:25 +08:00
|
|
|
set -g fish_prompt_git_status_unmerged !
|
2012-11-14 05:50:51 +08:00
|
|
|
|
2014-06-01 15:39:07 +08:00
|
|
|
set -g fish_prompt_git_status_order added modified renamed copied deleted untracked unmerged
|
2012-11-14 05:50:51 +08:00
|
|
|
|
2012-10-16 09:45:46 +08:00
|
|
|
function __terlar_git_prompt --description 'Write out the git prompt'
|
2016-11-28 13:27:22 +08:00
|
|
|
# If git isn't installed, there's nothing we can do
|
|
|
|
# Return 1 so the calling prompt can deal with it
|
2017-02-14 00:30:38 +08:00
|
|
|
if not command -sq git
|
2016-11-28 13:27:22 +08:00
|
|
|
return 1
|
|
|
|
end
|
2018-04-02 04:42:38 +08:00
|
|
|
set -l branch (git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
2016-11-28 13:27:22 +08:00
|
|
|
if test -z $branch
|
|
|
|
return
|
|
|
|
end
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
echo -n '|'
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2018-04-02 04:42:38 +08:00
|
|
|
set -l index (git status --porcelain 2>/dev/null|cut -c 1-2|sort -u)
|
2012-10-19 06:54:55 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
if test -z "$index"
|
|
|
|
set_color $fish_color_git_clean
|
|
|
|
echo -n $branch'✓'
|
|
|
|
set_color normal
|
|
|
|
return
|
|
|
|
end
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
set -l gs
|
|
|
|
set -l staged
|
2012-11-15 06:48:12 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
for i in $index
|
2019-01-27 02:19:24 +08:00
|
|
|
if string match -rq '^[AMRCD]' -- $i
|
2016-11-28 13:27:22 +08:00
|
|
|
set staged 1
|
|
|
|
end
|
2012-11-15 06:48:12 +08:00
|
|
|
|
2018-04-26 05:37:39 +08:00
|
|
|
# HACK: To allow matching a literal `??` both with and without `?` globs.
|
|
|
|
set -l dq '??'
|
2016-11-28 13:27:22 +08:00
|
|
|
switch $i
|
|
|
|
case 'A '
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a gs added
|
2016-11-28 13:27:22 +08:00
|
|
|
case 'M ' ' M'
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a gs modified
|
2016-11-28 13:27:22 +08:00
|
|
|
case 'R '
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a gs renamed
|
2016-11-28 13:27:22 +08:00
|
|
|
case 'C '
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a gs copied
|
2016-11-28 13:27:22 +08:00
|
|
|
case 'D ' ' D'
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a gs deleted
|
2018-04-26 05:37:39 +08:00
|
|
|
case "$dq"
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a gs untracked
|
2020-03-10 02:36:12 +08:00
|
|
|
case 'U*' '*U' DD AA
|
2017-08-05 09:02:24 +08:00
|
|
|
set -a gs unmerged
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
2012-10-16 09:45:46 +08:00
|
|
|
end
|
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
if set -q staged[1]
|
|
|
|
set_color $fish_color_git_staged
|
|
|
|
else
|
|
|
|
set_color $fish_color_git_dirty
|
|
|
|
end
|
2012-11-15 06:48:12 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
echo -n $branch'⚡'
|
2012-11-15 06:48:12 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
for i in $fish_prompt_git_status_order
|
|
|
|
if contains $i in $gs
|
|
|
|
set -l color_name fish_color_git_$i
|
|
|
|
set -l status_name fish_prompt_git_status_$i
|
2012-11-15 06:14:46 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
set_color $$color_name
|
|
|
|
echo -n $$status_name
|
|
|
|
end
|
2012-11-14 05:50:51 +08:00
|
|
|
end
|
2012-10-16 09:45:46 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
set_color normal
|
2012-10-16 09:45:46 +08:00
|
|
|
end
|