Optimize hg prompt

Mainly replace hg calls since python is slow to start.
This commit is contained in:
Fabian Homborg 2015-09-27 22:27:58 +02:00
parent 3a249bb549
commit 6f2f0cfce2

View file

@ -27,23 +27,32 @@ function __fish_hg_prompt --description 'Write out the hg prompt'
return 1 return 1
end end
set -l branch (hg branch ^/dev/null) # Find an hg directory above $PWD
# If there's no branch, there's no repository # without calling `hg root` because that's too slow
if test -z $branch set -l root
return set -l dir $PWD
while test $dir != "/"
if test -f $dir'/.hg/dirstate'
set root $dir"/.hg"
break
end
# Go up one directory
set -l dir (string replace -r '[^/]*/?$' '' $dir)
end end
# With "-q", hg bookmark will always output every bookmark if test -z "$root"
# So our only option is to filter it ourselves return 0
set -l bookmark (hg bookmark | string match ' \\**' | cut -d" " -f3) end
# Unfortunately, hg bookmark doesn't exit non-zero when there's no bookmark
if test -n "$bookmark" # Read branch and bookmark
set -l branch (cat $root/branch ^/dev/null; or echo default)
if set -l bookmark (cat $root/bookmarks.current ^/dev/null)
set branch "$branch/$bookmark" set branch "$branch/$bookmark"
end end
echo -n '|' echo -n '|'
set -l repo_status (hg status | cut -c 1-2 | sort -u) set -l repo_status (hg status | string sub -l 2 | sort -u)
# Show nice color for a clean repo # Show nice color for a clean repo
if test -z "$repo_status" if test -z "$repo_status"