2

I tried following the steps here to configure the prompt: https://nixos.wiki/wiki/Fish

Combined with the information here about the location and content of a basic file: https://fishshell.com/docs/current/faq.html#how-do-i-set-my-prompt

If I understood correctly the content of fish_prompt.fish should be:

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

After setting it this way the prompt is the same whether in a nix-shell or not and the variable $nix_shell_info does not get set.

How can I set it so that it works as intended?

Răzvan Flavius Panda
  • 21,730
  • 17
  • 111
  • 169

1 Answers1

4

You need to set the variable inside the function, otherwise it would always contain the value set when the file was loaded:

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

Edit: As cole-h pointed out on IRC, you also need to also change the single quotes containing the variable to double quotes or it will not be interpolated.

Jan Tojnar
  • 5,306
  • 3
  • 29
  • 49