From 9c829794597a201f441645b452b457717a61f96d Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 9 Feb 2019 15:46:13 +0100 Subject: [PATCH] Rename __fish_hg_prompt -> fish_hg_prompt --- share/functions/__fish_hg_prompt.fish | 100 +------------------------- share/functions/fish_hg_prompt.fish | 99 +++++++++++++++++++++++++ share/functions/fish_vcs_prompt.fish | 2 +- 3 files changed, 102 insertions(+), 99 deletions(-) create mode 100644 share/functions/fish_hg_prompt.fish diff --git a/share/functions/__fish_hg_prompt.fish b/share/functions/__fish_hg_prompt.fish index 63aa0a57c..b4ac91c8c 100644 --- a/share/functions/__fish_hg_prompt.fish +++ b/share/functions/__fish_hg_prompt.fish @@ -1,99 +1,3 @@ -# Adapted from __terlar_git_prompt - -set -g fish_color_hg_clean green -set -g fish_color_hg_modified yellow -set -g fish_color_hg_dirty red - -set -g fish_color_hg_added green -set -g fish_color_hg_renamed magenta -set -g fish_color_hg_copied magenta -set -g fish_color_hg_deleted red -set -g fish_color_hg_untracked yellow -set -g fish_color_hg_unmerged red - -set -g fish_prompt_hg_status_added '✚' -set -g fish_prompt_hg_status_modified '*' -set -g fish_prompt_hg_status_copied '⇒' -set -g fish_prompt_hg_status_deleted '✖' -set -g fish_prompt_hg_status_untracked '?' -set -g fish_prompt_hg_status_unmerged '!' - -set -g fish_prompt_hg_status_order added modified copied deleted untracked unmerged - -function __fish_hg_prompt --description 'Write out the hg prompt' - # If hg isn't installed, there's nothing we can do - # Return 1 so the calling prompt can deal with it - if not command -sq hg - return 1 - end - - set -l root (fish_print_hg_root) - or return 0 - - # Read branch and bookmark - set -l branch (cat $root/branch 2>/dev/null; or echo default) - if set -l bookmark (cat $root/bookmarks.current 2>/dev/null) - set branch "$branch|$bookmark" - end - - echo -n '|' - - # For some reason, "-q" still prints the same output, but ~20% faster. - # Disabling color and pager is always a good idea. - set -l repo_status (hg status -q --color never --pager never | string sub -l 2 | sort -u) - - # Show nice color for a clean repo - if test -z "$repo_status" - set_color $fish_color_hg_clean - echo -n "($branch)"'✓' - set_color normal - - # Handle modified or dirty (unknown state) - else - set -l hg_statuses - - # Take actions for the statuses of the files in the repo - for line in $repo_status - - # Add a character for each file status if we have one - # HACK: To allow this to work both with and without '?' globs - set -l q '?' - switch $line - case 'A ' - set -a hg_statuses added - case 'M ' ' M' - set -a hg_statuses modified - case 'C ' - set -a hg_statuses copied - case 'D ' ' D' - set -a hg_statuses deleted - case "$dq " - set -a hg_statuses untracked - case 'U*' '*U' 'DD' 'AA' - set -a hg_statuses unmerged - end - end - - if string match -qr '^[AMCD]' $repo_status - set_color $fish_color_hg_modified - else - set_color $fish_color_hg_dirty - end - - echo -n "($branch)"'⚡' - - # Sort status symbols - for i in $fish_prompt_hg_status_order - if contains -- $i $hg_statuses - set -l color_name fish_color_hg_$i - set -l status_name fish_prompt_hg_status_$i - - set_color $$color_name - echo -n $$status_name - end - end - - set_color normal - end - +function __fish_hg_prompt + fish_hg_prompt end diff --git a/share/functions/fish_hg_prompt.fish b/share/functions/fish_hg_prompt.fish new file mode 100644 index 000000000..584695f54 --- /dev/null +++ b/share/functions/fish_hg_prompt.fish @@ -0,0 +1,99 @@ +# Adapted from __terlar_git_prompt + +set -g fish_color_hg_clean green +set -g fish_color_hg_modified yellow +set -g fish_color_hg_dirty red + +set -g fish_color_hg_added green +set -g fish_color_hg_renamed magenta +set -g fish_color_hg_copied magenta +set -g fish_color_hg_deleted red +set -g fish_color_hg_untracked yellow +set -g fish_color_hg_unmerged red + +set -g fish_prompt_hg_status_added '✚' +set -g fish_prompt_hg_status_modified '*' +set -g fish_prompt_hg_status_copied '⇒' +set -g fish_prompt_hg_status_deleted '✖' +set -g fish_prompt_hg_status_untracked '?' +set -g fish_prompt_hg_status_unmerged '!' + +set -g fish_prompt_hg_status_order added modified copied deleted untracked unmerged + +function fish_hg_prompt --description 'Write out the hg prompt' + # If hg isn't installed, there's nothing we can do + # Return 1 so the calling prompt can deal with it + if not command -sq hg + return 1 + end + + set -l root (fish_print_hg_root) + or return 0 + + # Read branch and bookmark + set -l branch (cat $root/branch 2>/dev/null; or echo default) + if set -l bookmark (cat $root/bookmarks.current 2>/dev/null) + set branch "$branch|$bookmark" + end + + echo -n '|' + + # For some reason, "-q" still prints the same output, but ~20% faster. + # Disabling color and pager is always a good idea. + set -l repo_status (hg status -q --color never --pager never | string sub -l 2 | sort -u) + + # Show nice color for a clean repo + if test -z "$repo_status" + set_color $fish_color_hg_clean + echo -n "($branch)"'✓' + set_color normal + + # Handle modified or dirty (unknown state) + else + set -l hg_statuses + + # Take actions for the statuses of the files in the repo + for line in $repo_status + + # Add a character for each file status if we have one + # HACK: To allow this to work both with and without '?' globs + set -l q '?' + switch $line + case 'A ' + set -a hg_statuses added + case 'M ' ' M' + set -a hg_statuses modified + case 'C ' + set -a hg_statuses copied + case 'D ' ' D' + set -a hg_statuses deleted + case "$dq " + set -a hg_statuses untracked + case 'U*' '*U' 'DD' 'AA' + set -a hg_statuses unmerged + end + end + + if string match -qr '^[AMCD]' $repo_status + set_color $fish_color_hg_modified + else + set_color $fish_color_hg_dirty + end + + echo -n "($branch)"'⚡' + + # Sort status symbols + for i in $fish_prompt_hg_status_order + if contains -- $i $hg_statuses + set -l color_name fish_color_hg_$i + set -l status_name fish_prompt_hg_status_$i + + set_color $$color_name + echo -n $$status_name + end + end + + set_color normal + end + +end diff --git a/share/functions/fish_vcs_prompt.fish b/share/functions/fish_vcs_prompt.fish index 3df909695..6d94e6e06 100644 --- a/share/functions/fish_vcs_prompt.fish +++ b/share/functions/fish_vcs_prompt.fish @@ -1,5 +1,5 @@ function fish_vcs_prompt --description "Print the prompts for all available vcsen" fish_git_prompt - __fish_hg_prompt + fish_hg_prompt fish_svn_prompt end