From da601d4d69354bea0cfa125ae488f003e00deda5 Mon Sep 17 00:00:00 2001 From: nat-418 <93013864+nat-418@users.noreply.github.com> Date: Sun, 29 Jan 2023 16:54:39 +0100 Subject: [PATCH] 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 cf67709931ce5f61f05a31b00dbf1de9e705b52f) --- share/functions/fish_fossil_prompt.fish | 53 +++++++++++++++++++++++++ share/functions/fish_vcs_prompt.fish | 1 + 2 files changed, 54 insertions(+) create mode 100644 share/functions/fish_fossil_prompt.fish diff --git a/share/functions/fish_fossil_prompt.fish b/share/functions/fish_fossil_prompt.fish new file mode 100644 index 000000000..5c42f47e8 --- /dev/null +++ b/share/functions/fish_fossil_prompt.fish @@ -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_info + string match --regex --quiet \ + '^tags:\s*(?.*)$' $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 diff --git a/share/functions/fish_vcs_prompt.fish b/share/functions/fish_vcs_prompt.fish index 4b1723d36..b3a42cdb6 100644 --- a/share/functions/fish_vcs_prompt.fish +++ b/share/functions/fish_vcs_prompt.fish @@ -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.