mirror of
https://github.com/fish-shell/fish-shell
synced 2024-09-23 07:52:06 +00:00
Optimize hg prompt
Mainly replace hg calls since python is slow to start.
This commit is contained in:
parent
3a249bb549
commit
6f2f0cfce2
1 changed files with 19 additions and 10 deletions
|
@ -27,23 +27,32 @@ function __fish_hg_prompt --description 'Write out the hg prompt'
|
|||
return 1
|
||||
end
|
||||
|
||||
set -l branch (hg branch ^/dev/null)
|
||||
# If there's no branch, there's no repository
|
||||
if test -z $branch
|
||||
return
|
||||
# Find an hg directory above $PWD
|
||||
# without calling `hg root` because that's too slow
|
||||
set -l root
|
||||
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
|
||||
|
||||
# With "-q", hg bookmark will always output every bookmark
|
||||
# So our only option is to filter it ourselves
|
||||
set -l bookmark (hg bookmark | string match ' \\**' | cut -d" " -f3)
|
||||
# Unfortunately, hg bookmark doesn't exit non-zero when there's no bookmark
|
||||
if test -n "$bookmark"
|
||||
if test -z "$root"
|
||||
return 0
|
||||
end
|
||||
|
||||
# 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"
|
||||
end
|
||||
|
||||
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
|
||||
if test -z "$repo_status"
|
||||
|
|
Loading…
Reference in a new issue