aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Fabian Homborg <FHomborg@gmail.com>2015-09-27 22:27:58 +0200
committerGravatar Fabian Homborg <FHomborg@gmail.com>2015-12-31 14:21:37 +0100
commit6f2f0cfce2afe888878b4aaaeef488fcd2bd02a0 (patch)
tree266d5d3085ea996c05b0a0a3a6dc02ff877e9968
parent3a249bb5495a3366cb98a5cadaf22a141f6eed99 (diff)
Optimize hg prompt
Mainly replace hg calls since python is slow to start.
-rw-r--r--share/functions/__fish_hg_prompt.fish29
1 files changed, 19 insertions, 10 deletions
diff --git a/share/functions/__fish_hg_prompt.fish b/share/functions/__fish_hg_prompt.fish
index 20a6d3ba..783eae24 100644
--- a/share/functions/__fish_hg_prompt.fish
+++ b/share/functions/__fish_hg_prompt.fish
@@ -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"