Skip to content

Commit

Permalink
Optimize hg prompt
Browse files Browse the repository at this point in the history
Mainly replace hg calls since python is slow to start.
  • Loading branch information
faho committed Sep 27, 2015
1 parent aa37b40 commit 3ae99e3
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions share/functions/__fish_hg_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3ae99e3

Please sign in to comment.