2014-11-29 13:15:12 +00:00
|
|
|
# Adapted from __terlar_git_prompt
|
|
|
|
|
|
|
|
set -g fish_color_hg_clean green
|
|
|
|
set -g fish_color_hg_modified yellow
|
|
|
|
set -g fish_color_hg_dirty red
|
|
|
|
|
|
|
|
set -g fish_color_hg_added green
|
|
|
|
set -g fish_color_hg_renamed magenta
|
|
|
|
set -g fish_color_hg_copied magenta
|
|
|
|
set -g fish_color_hg_deleted red
|
|
|
|
set -g fish_color_hg_untracked yellow
|
|
|
|
set -g fish_color_hg_unmerged red
|
|
|
|
|
|
|
|
set -g fish_prompt_hg_status_added '✚'
|
|
|
|
set -g fish_prompt_hg_status_modified '*'
|
|
|
|
set -g fish_prompt_hg_status_copied '⇒'
|
|
|
|
set -g fish_prompt_hg_status_deleted '✖'
|
|
|
|
set -g fish_prompt_hg_status_untracked '?'
|
|
|
|
set -g fish_prompt_hg_status_unmerged '!'
|
|
|
|
|
|
|
|
set -g fish_prompt_hg_status_order added modified copied deleted untracked unmerged
|
|
|
|
|
|
|
|
function __fish_hg_prompt --description 'Write out the hg prompt'
|
2015-10-01 00:06:18 +00:00
|
|
|
# If hg isn't installed, there's nothing we can do
|
|
|
|
# Return 1 so the calling prompt can deal with it
|
2017-02-13 16:30:38 +00:00
|
|
|
if not command -sq hg
|
2015-10-01 00:06:18 +00:00
|
|
|
return 1
|
|
|
|
end
|
2015-09-26 18:40:48 +00:00
|
|
|
|
2015-10-01 00:06:18 +00:00
|
|
|
# Find an hg directory above $PWD
|
|
|
|
# without calling `hg root` because that's too slow
|
|
|
|
set -l root
|
2018-10-06 23:53:02 +00:00
|
|
|
set -l dir (pwd -P)
|
2015-09-27 20:27:58 +00:00
|
|
|
while test $dir != "/"
|
2015-10-01 00:06:18 +00:00
|
|
|
if test -f $dir'/.hg/dirstate'
|
|
|
|
set root $dir"/.hg"
|
|
|
|
break
|
|
|
|
end
|
|
|
|
# Go up one directory
|
2018-04-02 13:24:50 +00:00
|
|
|
set dir (string replace -r '[^/]*/?$' '' $dir)
|
2014-11-29 13:15:12 +00:00
|
|
|
end
|
|
|
|
|
2015-10-01 00:06:18 +00:00
|
|
|
if test -z "$root"
|
|
|
|
return 0
|
|
|
|
end
|
2015-09-27 20:27:58 +00:00
|
|
|
|
2015-10-01 00:06:18 +00:00
|
|
|
# Read branch and bookmark
|
2018-04-01 20:42:38 +00:00
|
|
|
set -l branch (cat $root/branch 2>/dev/null; or echo default)
|
|
|
|
if set -l bookmark (cat $root/bookmarks.current 2>/dev/null)
|
2015-10-01 00:06:18 +00:00
|
|
|
set branch "$branch|$bookmark"
|
|
|
|
end
|
2015-09-26 18:41:18 +00:00
|
|
|
|
2014-11-29 13:15:12 +00:00
|
|
|
echo -n '|'
|
|
|
|
|
2018-05-08 20:52:16 +00:00
|
|
|
# For some reason, "-q" still prints the same output, but ~20% faster.
|
|
|
|
# Disabling color and pager is always a good idea.
|
|
|
|
set -l repo_status (hg status -q --color never --pager never | string sub -l 2 | sort -u)
|
2014-11-29 13:15:12 +00:00
|
|
|
|
|
|
|
# Show nice color for a clean repo
|
|
|
|
if test -z "$repo_status"
|
|
|
|
set_color $fish_color_hg_clean
|
2015-09-28 19:11:36 +00:00
|
|
|
echo -n "($branch)"'✓'
|
2014-11-29 13:15:12 +00:00
|
|
|
set_color normal
|
|
|
|
|
2015-10-01 00:06:18 +00:00
|
|
|
# Handle modified or dirty (unknown state)
|
2014-11-29 13:15:12 +00:00
|
|
|
else
|
|
|
|
set -l hg_statuses
|
|
|
|
|
|
|
|
# Take actions for the statuses of the files in the repo
|
|
|
|
for line in $repo_status
|
|
|
|
|
|
|
|
# Add a character for each file status if we have one
|
2018-04-25 21:37:39 +00:00
|
|
|
# HACK: To allow this to work both with and without '?' globs
|
|
|
|
set -l q '?'
|
2014-11-29 13:15:12 +00:00
|
|
|
switch $line
|
2016-11-28 05:27:22 +00:00
|
|
|
case 'A '
|
2017-08-05 01:02:24 +00:00
|
|
|
set -a hg_statuses added
|
2016-11-28 05:27:22 +00:00
|
|
|
case 'M ' ' M'
|
2017-08-05 01:02:24 +00:00
|
|
|
set -a hg_statuses modified
|
2016-11-28 05:27:22 +00:00
|
|
|
case 'C '
|
2017-08-05 01:02:24 +00:00
|
|
|
set -a hg_statuses copied
|
2016-11-28 05:27:22 +00:00
|
|
|
case 'D ' ' D'
|
2017-08-05 01:02:24 +00:00
|
|
|
set -a hg_statuses deleted
|
2018-04-25 21:37:39 +00:00
|
|
|
case "$dq "
|
2017-08-05 01:02:24 +00:00
|
|
|
set -a hg_statuses untracked
|
2016-11-28 05:27:22 +00:00
|
|
|
case 'U*' '*U' 'DD' 'AA'
|
2017-08-05 01:02:24 +00:00
|
|
|
set -a hg_statuses unmerged
|
2014-11-29 13:15:12 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-08 13:10:03 +00:00
|
|
|
if string match -qr '^[AMCD]' $repo_status
|
2014-11-29 13:15:12 +00:00
|
|
|
set_color $fish_color_hg_modified
|
|
|
|
else
|
|
|
|
set_color $fish_color_hg_dirty
|
|
|
|
end
|
|
|
|
|
2015-09-28 19:11:36 +00:00
|
|
|
echo -n "($branch)"'⚡'
|
2014-11-29 13:15:12 +00:00
|
|
|
|
|
|
|
# Sort status symbols
|
|
|
|
for i in $fish_prompt_hg_status_order
|
2015-09-27 14:30:37 +00:00
|
|
|
if contains -- $i $hg_statuses
|
2014-11-29 13:15:12 +00:00
|
|
|
set -l color_name fish_color_hg_$i
|
|
|
|
set -l status_name fish_prompt_hg_status_$i
|
|
|
|
|
|
|
|
set_color $$color_name
|
|
|
|
echo -n $$status_name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
set_color normal
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|