0

When trying to temporarily disable a fish_mode_prompt function:

function get_input -a prompt var_name -d 'get user input and place it in var_name'
  functions -c fish_mode_prompt fish_mode_prompt_tmp
  functions -e fish_mode_prompt
  read --global --prompt-str="$prompt" $var_name
  functions -c fish_mode_prompt_tmp fish_mode_prompt
  functions -e fish_mode_prompt_tmp
end

I get the following error:

functions: Function “fish_mode_prompt” already exists. Cannot create copy “fish_mode_prompt_tmp”
~/.config/fishdots/plugins/fishdots_crm/init/rc1.d/01.functions.fish (line 114):
  functions -c fish_mode_prompt_tmp fish_mode_prompt
  ^
in function “get_input”
        called on standard input
        with parameter list “hello world:  charlie”


       functionsfunctions - print or erase functions
        -

   Synopsis
       functions [ -a | --all ] [ -n | --names ]
       functions [ -D | --details ] [ -v ] FUNCTION
       functions -c OLDNAME NEWNAME
       functions -d DESCRIPTION FUNCTION
       functions [ -e | -q ] FUNCTIONS...

functions: Type “help functions” for related documentation

I'm not entirely sure what's happening here. Should this work?

Andrew Matthews
  • 3,006
  • 2
  • 29
  • 42

1 Answers1

2

See https://github.com/fish-shell/fish-shell/issues/741. functions --erase does not actually remove the file containing the autoloaded function definition.

Rather than attempt to rename the function in that fashion just replace it with a dummy implementation:

function fish_mode_prompt; end
read --global --prompt-str="$prompt" $var_name
function -e fish_mode_prompt

But I don't understand why you would want to do this. If you're using vi mode you really should just let its state indicator be present at all times. Even when executing a read command. If you dislike the state indicator I would simply define your own ~/.config/fish/functions/fish_mode_prompt.fish autoloaded script with an empty fish_mode_prompt function.

Kurtis Rader
  • 6,734
  • 13
  • 20
  • I like the look of this, but I can't get it to work - syntax error on the nested function def? - probably because I am stuck on 2.7.1. I'll try to coax NixOS to give me 3.* and see if it works then. – Andrew Matthews Jun 16 '19 at 23:29
  • @AndrewMatthews Works for me; although I see I have a typo in my answer. The `function -e` should be `functions -e`. You will get a syntax error without that fix. – Kurtis Rader Jun 17 '19 at 21:12