Search code examples
promptfish

fish shell disable all prompts temporarily


I wanted to create a simple text entry system to provide input to a script. I created a helper function:

function get_input -a prompt var_name -d 'get user input and place it in var_name'
  echo -n "$prompt"
  read --global $var_name
  echo ""
end

but I have a fairly lengthy prompt setup, so my read prompt looks ugly:

tsrep prod2 d235108 ~> nsstltlb13 d235108@nsda3bpldv40 ~/.c/f/p/fishdots_notes> get_input 'hello world' charlie
hello world
tsrep prod2 d235108 ~> nsstltlb13 read> bonjour le monde!

So I tried to disable the fish_prompt function, using a rename:

function get_input -a prompt var_name -d 'get user input and place it in var_name'
  functions -c fish_prompt fish_prompt_tmp
  functions -e fish_prompt
  echo -n "$prompt"
  read --global $var_name
  echo ""
  functions -c fish_prompt_tmp fish_prompt
  functions -e fish_prompt_tmp
end

but it had absolutely no effect.

What am I missing?


Solution

  • read uses its own prompt, and does not call fish_prompt.

    You can specify the prompt for read with an option:

    read --global --prompt-str="$prompt" $var_name
    

    You can also use a real command:

    read --global --prompt='echo something: ' $var_name