fish shell 暂时禁用所有提示

fish shell disable all prompts temporarily

我想创建一个简单的文本输入系统来为脚本提供输入。我创建了一个辅助函数:

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

但是我的提示设置相当冗长,所以我的 read 提示看起来很难看:

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!

所以我尝试禁用 fish_prompt 功能,使用重命名:

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

但完全没有效果。

我错过了什么?

read 使用自己的提示,不调用 fish_prompt.

您可以使用以下选项指定 read 的提示:

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

你也可以使用真正的命令:

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