我尝试按照下面的步骤配置提示符:https://nixos.wiki/wiki/Fish
结合此处有关基本文件的位置和内容的信息:https://fishshell.com/docs/current/faq.html#how-do-i-set-my-prompt
如果我没理解错的话,fish_prompt.fish的内容应该是:
set -l nix_shell_info (
if test -n "$IN_NIX_SHELL"
echo -n "<nix-shell> "
end
)
function fish_prompt
set_color $fish_color_cwd
echo -n (prompt_pwd)
set_color normal
echo -n -s ' $nix_shell_info ~>'
end以这种方式设置之后,无论是否在nix-shell中,提示都是相同的,并且不会设置变量$nix_shell_info。
我如何设置它,使其按预期工作?
发布于 2020-04-17 08:41:22
您需要在函数内部设置变量,否则它将始终包含加载文件时设置的值:
function fish_prompt
set -l nix_shell_info (
if test -n "$IN_NIX_SHELL"
echo -n "<nix-shell> "
end
)
set_color $fish_color_cwd
echo -n (prompt_pwd)
set_color normal
echo -n -s " $nix_shell_info ~>"
end编辑:正如cole-h在IRC上指出的那样,您还需要将包含变量的单引号更改为双引号,否则将不会对其进行插值。
https://stackoverflow.com/questions/61262216
复制相似问题