Extract code to print hg root from the prompt

This is useful in other prompts, and potentially also to users.

Don't use a dunderscore because we do way too many of them.
This commit is contained in:
Fabian Homborg 2018-11-30 20:57:59 +01:00
parent 60f8eda5c4
commit 176c84fb9f
2 changed files with 24 additions and 16 deletions

View file

@ -27,22 +27,8 @@ function __fish_hg_prompt --description 'Write out the hg prompt'
return 1 return 1
end end
# Find an hg directory above $PWD set -l root (fish_print_hg_root)
# without calling `hg root` because that's too slow or return 0
set -l root
set -l dir (pwd -P)
while test $dir != "/"
if test -f $dir'/.hg/dirstate'
set root $dir"/.hg"
break
end
# Go up one directory
set dir (string replace -r '[^/]*/?$' '' $dir)
end
if test -z "$root"
return 0
end
# Read branch and bookmark # Read branch and bookmark
set -l branch (cat $root/branch 2>/dev/null; or echo default) set -l branch (cat $root/branch 2>/dev/null; or echo default)

View file

@ -0,0 +1,22 @@
function fish_print_hg_root
# If hg isn't installed, there's nothing we can do
if not command -sq hg
return 1
end
# Find an hg directory above $PWD
# without calling `hg root` because that's too slow
set -l root
set -l dir (pwd -P)
while test $dir != "/"
if test -f $dir'/.hg/dirstate'
echo $dir/.hg
return 0
end
# Go up one directory
set dir (string replace -r '[^/]*/?$' '' $dir)
end
return 1
end