gpakosz / .tmux

🇫🇷 Oh my tmux! My self-contained, pretty & versatile tmux configuration made with ❤️
MIT License
21.79k stars 3.36k forks source link

`gh-200+221+439+586`: Cannot use TPM #624

Closed sylph1o closed 1 year ago

sylph1o commented 1 year ago

Hi @gpakosz :wave:

I have tested the branch gh-200+221+439+586 without modifying tmux.conf (all my settings are in my tmux.conf.local).

I get the following message when loading the configuration: 'Cannot use tpm which assumes a globally installed tmux'.

Although I don't understand completely the way TMUX_PROGRAM is set, I guess the problem could be that, for me, command -v tmux returns

alias tmux=_zsh_tmux_plugin_run

This is because I am using the tmux plugin from oh-my-zsh, which defines _zsh_tmux_plugin_run and sets this alias.

I don't understand enough what happens in tmux.conf to propose a fix, but I'd be happy to provide more information and test possible solutions.

tmux version: 3.3a

gpakosz commented 1 year ago

Hello @sylph1o 👋

I pushed a commit in the gh-200+221+439+586 branch to fix that detection

sylph1o commented 1 year ago

Thanks for the quick reply. I see your fix, and I tried the latest version from gh-200+221+439+586. It didn't change the issue, and I think I know why.

To get the output of command -v tmux that I gave above, I ran the command in my terminal, i.e. an interactive zsh session. However, as I understand it, the code in tmux.conf is run in a non-interactive sh session (sh is linked to bash on my computer), meaning that my zsh aliases and plugins are not loaded. The information I gave was not relevant, sorry for misleading you.

To get the values seen by the functions in tmux.conf, I inserted a few lines above if [ command -v tmux ... (line 1420, where the test fails even though it should not) to return the relevant values (e.g. echo $TMUX_PROGRAM > some_file). Below is what I get

> echo $TMUX_PROGRAM
/usr/bin/tmux

> command -v tmux
tmux

> which -a tmux
/usr/sbin/tmux
/sbin/tmux
/bin/tmux
/usr/bin/tmux
/bin/tmux

I don't understand the output of command -v tmux. When I run in my terminal sh -c 'command -v tmux', I get /usr/sbin/tmux, which is coherent with the output of which -a tmux.

Just in case, I have also tried disabling the tmux plugin of oh-my-zsh, and starting the tmux server and session from a bash shell (after setting bash as my default shell, too). Neither changed the values that I list above (the ones seen by the functions in tmux.conf).

sylph1o commented 1 year ago

As a side note, even if command -v tmux returned the same as in my terminal and as which tmux (i.e. /usr/sbin/tmux), that would not match $TMUX_PROGRAM. Both /usr/sbin/tmux and /usr/bin/tmux are the same file (hardlinks) but /usr/sbin is first in PATH. None of this is my doing, this is the normal setup in Arch Linux.

However, which -a tmux | grep -q $TMUX_PROGRAM would give a positive match, but I don't know if that condition checks what you want to check in line 1420.

P.S. I just tried to replace line 1420 with

#     if $( which -a tmux | grep -q "$TMUX_PROGRAM" ); then

and then the configuration loads TPM, without any other message or visible error. I don't know if this is acceptable as a general solution, only that it seems to work on my computer. Of course, so would if true; then ... I was curious to see if there were other problems further in the configuration, and there does not seem to be.

gpakosz commented 1 year ago
> which -a tmux
/usr/sbin/tmux
/sbin/tmux
/bin/tmux
/usr/bin/tmux
/bin/tmux

First time I see this! Why so many?

I don't understand the output of command -v tmux. When I run in my terminal sh -c 'command -v tmux', I get /usr/sbin/tmux, which is coherent with the output of which -a tmux.

My fix is indeed incorrect, that's because .tmux.conf defines a tmux() function to make sure it talks to the proper tmux program that may not be in the pass. Comparatively, TPM uses tmux and assumes it's installed globally.

What Oh my tmux! is trying to guard against is: TPM can't work if there's no tmux program in $PATH while Oh my tmux! can now generally work if you launch it with a locally compiled version of tmux that may be renamed to something else, e.g. tmux-3.3a.

Pushed another tentative fix

sylph1o commented 1 year ago

Thanks for the explanation, it makes more sense now.

First time I see this! Why so many?

/bin, /sbin and /usr/sbin are all symlinks to /usr/bin (I was wrong to mention hardlinks in my previous comment). This is defined in the file system hierarchy for OS using the systemd service manager (see file-hierarchy(7)), for compatibility.

Additionally, /bin/tmux appears twice because /bin appears twice in the PATH seen by the functions of Oh my tmux!. I don't know why: in my interactive shell, sh -c 'echo $PATH' returns only one occurrence of /bin.

Pushed another tentative fix

I have just tried it, and it works! This solves my issue.

I must say I'm very grateful to see the support for different locations of the configuration file. Having to patch manually was the only (very minor) inconvenience for me so far. This is an appreciable quality-of-life improvement, thanks! :pray: