简体   繁体   中英

Problem modifying PATH variable in fish config

I have the following configuration in ~/.config/fish/conf.d/python.fish:

# Initialise pyenv if found
echo "Running python config"
if status --is-interactive && test -d "$HOME/.pyenv"
    echo "Inside pyenv if"
    set -pxg PATH $HOME/.pyenv/bin $HOME/.pyenv/shims
    source ("$HOME/.pyenv/bin/pyenv" init - | psub)
    echo "End pyenv if"
end

# Poetry settings
if status --is-interactive && test -d "$HOME/.pyenv"
    set -xg POETRY_VIRTUALENVS_IN_PROJECT 1
    set -xg POETRY_VIRTUALENVS_CREATE 1
    set -pxg PATH $HOME/.poetry/bin
end
echo "End python config"

Every single echo command in the configuration is executed when I am creating a new shell, but the PATH variable is not modified. However, the POETRY_ variables show up as expected.

But things work as expected if I source the file in an existing shell with

source ~/.config/fish/conf.d/python.fish

What could possibly be wrong here?

Update: The problem only occurs inside of tmux, and not when I am starting terminals like Alacritty or Kitty. But all echo commands is still run inside tmux.

This was a Debian bug - they added configuration that reset $PATH, and it happened after the user's configuration snippets but before config.fish.

This appears to be fixed in Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1000199 . Now they merely add the default directories instead of replacing $PATH entirely.

Because config.fish is read after all the conf.d files, you can always use config.fish to override anything done in the snippets, like if your vendor breaks things.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM