【问题标题】:configuring fish shell prompt inside nix-shell在 nix-shell 中配置 fish shell 提示
【发布时间】:2020-04-17 00:20:47
【问题描述】:

我尝试按照此处的步骤配置提示: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 没有设置。

如何设置它以使其按预期工作?

【问题讨论】:

  • 有人可以证明为什么需要投反对票以便我改进问题吗?

标签: shell fish nix nix-shell


【解决方案1】:

你需要在函数内部设置变量,否则它总是包含加载文件时设置的值:

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 上指出的那样,您还需要将包含变量的单引号更改为双引号,否则将不会被插值。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-03-04
  • 2016-01-06
  • 1970-01-01
  • 1970-01-01
  • 2017-11-09
  • 2021-12-20
  • 2011-02-15
  • 1970-01-01
相关资源
最近更新 更多