feat: add support for fossil-scm in prompt (#9500)

* feat: add support for fossil-scm in prompt

* fix: change directory testing and string matching

(cherry picked from commit cf67709931)
This commit is contained in:
nat-418 2023-01-29 16:54:39 +01:00 committed by Fabian Boehm
parent f39bc9317d
commit da601d4d69
2 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,53 @@
function fish_fossil_prompt --description 'Write out the fossil prompt'
# Bail if fossil is not available
if not command -sq fossil
return 1
end
# Bail if not a fossil checkout
if not fossil ls &> /dev/null
return 127
end
# Parse fossil info
set -l fossil_info (fossil info)
string match --regex --quiet \
'^project-name:\s*(?<fossil_project_name>.*)$' $fossil_info
string match --regex --quiet \
'^tags:\s*(?<fossil_tags>.*)$' $fossil_info
echo -n ' ['
set_color --bold magenta
echo -n $fossil_project_name
set_color normal
echo -n ':'
set_color --bold yellow
echo -n $fossil_tags
set_color normal
# Parse fossil status
set -l fossil_status (fossil status)
if string match --quiet 'ADDED*' $fossil_status
set_color --bold green
echo -n '+'
end
if string match --quiet 'DELETED*' $fossil_status
set_color --bold red
echo -n '-'
end
if string match --quiet 'MISSING*' $fossil_status
set_color --bold red
echo -n '!'
end
if string match --quiet 'RENAMED*' $fossil_status
set_color --bold yellow
echo -n '→'
end
if string match --quiet 'CONFLICT*' $fossil_status
set_color --bold green
echo -n '×'
end
set_color normal
echo -n ']'
end

View file

@ -3,6 +3,7 @@ function fish_vcs_prompt --description "Print all vcs prompts"
# This is so we don't try svn if git already worked.
fish_git_prompt $argv
or fish_hg_prompt $argv
or fish_fossil_prompt $argv
# The svn prompt is disabled by default because it's quite slow on common svn repositories.
# To enable it uncomment it.
# You can also only use it in specific directories by checking $PWD.