asdf-vm / asdf

Extendable version manager with support for Ruby, Node.js, Elixir, Erlang & more
https://asdf-vm.com/
MIT License
21.62k stars 769 forks source link

bug: Using tmux asdf install adds tmux binary to path within tmux #1114

Open primeapple opened 2 years ago

primeapple commented 2 years ago

Describe the Bug

When using the asdf tmux install and start in TMUX the actual tmux binary is added to the path. This means, that running which tmux does not give me the tmux shim, but instead the actual currently installed binary path.

This creates problems when, for example, using which tmux in scripts, where it needs to point to the shim, tmux continuum for example

I tested this on my desktop (Manjaro KDE, fish shell, extensive .tmux.conf), as well as in a Virtual Machine (Manjaro Cinnamon, Bash Shell, no .tmux.conf).

I already asked the tmux/tmux guys, but they told me it's not a tmux issue: https://github.com/tmux/tmux/issues/2992

Steps to Reproduce

tmux has-session
# no server running on /tmp/tmux-1000/default
echo $PATH
# /home/me/.asdf/shims /home/me/.asdf/bin /home/me/.bin /usr/local/sbin /usr/local/bin /usr/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl
tmux
# now inside tmux
echo $PATH
# /home/me/.asdf/shims /home/me/.asdf/bin /home/me/.bin /home/me/.asdf/installs/tmux/3.2a/bin /usr/local/sbin /usr/local/bin /usr/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl
# notice how we got an additional entry for the actual tmux binary
tmux run 'echo $PATH'  # same result with ':' instead of space between the paths, when running PREFIX ->  :run 'echo $PATH'
# /home/me/.asdf/installs/tmux/3.2a/bin /home/me/.asdf/shims /home/me/.asdf/bin /home/me/.bin /usr/local/sbin /usr/local/bin /usr/bin /usr/bin/site_perl /usr/bin/vendor_perl /usr/bin/core_perl
# notice how the additional tmux binary entry now went in front of the path

Expected Behaviour

There are 2 solutions to this:

  1. When going into tmux, it should not add the asdf tmux binary to the path
  2. If 1. is not working, than at least when running tmux commands within tmux, the asdf tmux binary should not get in front of the path.

Actual Behaviour

Already described above, please if you want more knowledge, look at https://github.com/tmux/tmux/issues/2992#issuecomment-986018921

Environment

OS:
Linux mypc 5.10.79-1-MANJARO #1 SMP PREEMPT Fri Nov 12 20:26:09 UTC 2021 x86_64 GNU/Linux

SHELL:
fish, version 3.3.1

ASDF VERSION:
v0.8.1

ASDF ENVIRONMENT VARIABLES:
ASDF_DIR=/home/me/.asdf

ASDF INSTALLED PLUGINS:
bat                          https://gitlab.com/wt0f/asdf-bat
exa                          https://github.com/nyrst/asdf-exa
fd                           https://gitlab.com/wt0f/asdf-fd.git
jq                           https://github.com/azmcode/asdf-jq
neovim                       https://github.com/richin13/asdf-neovim.git
nodejs                       https://github.com/asdf-vm/asdf-nodejs.git
tmux                         https://github.com/aphecetche/asdf-tmux.git

asdf plugins affected (if relevant)

aphecetche/asdf-tmux

jthegedus commented 2 years ago

Can you clarify something, I am confused. Do you want the asdf shim, the asdf install or the regular non-asdf installed tmux? Are you saying you don't want /home/me/.asdf/installs/tmux/3.2a/bin to appear in your PATH? I am not sure how it is being added. Have you raised this with the tmux plugin author?

primeapple commented 2 years ago

I want the asdf shim in my path within tmux. I never want /home/me/.asdf/installs/tmux/3.2a/bin in my path. I don't even have regular non-asdf tmux installed (but if I had I guess it is always in the path because of /usr/bin/, but with less precedence than the asdf tmux) ;-)

The problem is not because of any plugin (it happens without any plugins installed), it just leads to issues in combination with the plugin. That's how I found it.

Thanks for answering. I know it sounds complicated, because there are so many tmux words in it :D

primeapple commented 2 years ago

Update:

There was a very helpful answer by user @systemmonkey42 in https://github.com/tmux/tmux/issues/2992#issuecomment-988344774

What he found was that, whenever we run an application, it's actual binary is added to the path, BEFORE the shim executables of this application.

To quote him:

vim

asdf plugin add vim asdf install vim $ which vim /home/admin/.asdf/shims/vim $ vim +'!which vim' /home/admin/.asdf/installs/vim/8.2.3757/bin/vim

nodejs

asdf plugin add nodejs asdf plugin install nodejs $ which node /home/admin/.asdf/shims/node $ node -e "childprocess.exec('which node',(,o)=>console.log(o))" /home/admin/.asdf/installs/nodejs/17.2.0/bin/node

tmux

asdf plugin add tmux asdf plugin install tmux $ which tmux /home/admin/.asdf/shims/tmux $ tmux new-session -d $ tmux run-shell 'which tmux' /home/admin/.asdf/installs/tmux/3.2a/bin/tmux

Is this an actual design by asdf? Is this a bug? What would be a workaround for it (since I don't want it, at least in the tmux case).

systemmonkey42 commented 2 years ago

If I might weigh in here, there is a "bug", but I think it might be intentional.

When I use 'asdf' to launch vim, it will prepend the path to the specified vim version to $PATH, then launch vim. Similar to

PATH=<path to asdf  managed vim>:$PATH  vim "$@"

The problem we are talking about is when using asdf to launch tmux, each tmux pane launches a new shell, which sources .asdf/asdf.sh on startup.

As a side effect of this, ~/.asdf/bin and ~/.asdf/shim are re-inserted at the beginning of $PATH in each pane within tmux.

If I later run a tmux command, such as tmux split-window, the SHIM is found in the path, and risks running the wrong tmux binary depending on any local configuration. (Which may break the client/server protocols used)

I would suggest the path to any application like tmux should remain before ~/.asdf/shims.

As a workaround, I don't source ~/.asdf/asdf.sh in any shell within tmux. This isn't perfect but mostly works.

Does this make sense? Thx