fish-shell/share/functions/fish_fossil_prompt.fish
nat-418 cf67709931
feat: add support for fossil-scm in prompt (#9500)
* feat: add support for fossil-scm in prompt

* fix: change directory testing and string matching
2023-01-29 16:54:39 +01:00

53 lines
1.3 KiB
Fish
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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