From 6f9f7632f3b153d64814652390370e4d60677ef3 Mon Sep 17 00:00:00 2001 From: Cristian Prieto Date: Fri, 13 Jan 2017 02:07:41 +1100 Subject: [PATCH] Added default mode prompt function (#3727) * Added new function for the default prompt mode Now fish mode prompt will call fish_default_mode_prompt, this will solve #3641 * Added function description * Change wording for documentation about default mode prompt * Finish changes requested in code review --- doc_src/index.hdr.in | 2 +- share/functions/fish_default_mode_prompt.fish | 23 +++++++++++++++++++ share/functions/fish_mode_prompt.fish | 22 ++---------------- 3 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 share/functions/fish_default_mode_prompt.fish diff --git a/doc_src/index.hdr.in b/doc_src/index.hdr.in index 577082f07..b276aec90 100644 --- a/doc_src/index.hdr.in +++ b/doc_src/index.hdr.in @@ -1050,7 +1050,7 @@ function fish_user_key_bindings end \endfish -When in vi-mode, the `fish_mode_prompt` function will display a mode indicator to the left of the prompt. The `fish_vi_cursor` function will be used to change the cursor's shape depending on the mode in supported terminals. To disable this feature, override it with an empty function. +When in vi-mode, the `fish_mode_prompt` function will display a mode indicator to the left of the prompt. The `fish_vi_cursor` function will be used to change the cursor's shape depending on the mode in supported terminals. To disable this feature, override it with an empty function. To display the mode elsewhere (like in your right prompt), use the output of the `fish_default_mode_prompt` function. \subsubsection vi-mode-command Command mode diff --git a/share/functions/fish_default_mode_prompt.fish b/share/functions/fish_default_mode_prompt.fish new file mode 100644 index 000000000..638c07f9e --- /dev/null +++ b/share/functions/fish_default_mode_prompt.fish @@ -0,0 +1,23 @@ +function fish_default_mode_prompt --description "Display the default mode for the prompt" + # Do nothing if not in vi mode + if test "$fish_key_bindings" = "fish_vi_key_bindings" + or test "$fish_key_bindings" = "fish_hybrid_key_bindings" + switch $fish_bind_mode + case default + set_color --bold --background red white + echo '[N]' + case insert + set_color --bold --background green white + echo '[I]' + case replace-one + set_color --bold --background green white + echo '[R]' + case visual + set_color --bold --background magenta white + echo '[V]' + end + set_color normal + echo -n ' ' + end +end + diff --git a/share/functions/fish_mode_prompt.fish b/share/functions/fish_mode_prompt.fish index 06737d4f3..294ebeebb 100644 --- a/share/functions/fish_mode_prompt.fish +++ b/share/functions/fish_mode_prompt.fish @@ -1,23 +1,5 @@ # The fish_mode_prompt function is prepended to the prompt function fish_mode_prompt --description "Displays the current mode" - # Do nothing if not in vi mode - if test "$fish_key_bindings" = "fish_vi_key_bindings" - or test "$fish_key_bindings" = "fish_hybrid_key_bindings" - switch $fish_bind_mode - case default - set_color --bold --background red white - echo '[N]' - case insert - set_color --bold --background green white - echo '[I]' - case replace-one - set_color --bold --background green white - echo '[R]' - case visual - set_color --bold --background magenta white - echo '[V]' - end - set_color normal - echo -n ' ' - end + # To reuse the mode indicator use this function instead + fish_default_mode_prompt end