mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 21:03:12 +00:00
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:
parent
60f8eda5c4
commit
176c84fb9f
2 changed files with 24 additions and 16 deletions
|
@ -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)
|
||||||
|
|
22
share/functions/fish_print_hg_root.fish
Normal file
22
share/functions/fish_print_hg_root.fish
Normal 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
|
||||||
|
|
Loading…
Reference in a new issue