gpakosz / .tmux

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

Changing to config files in ~.config/tmux #439

Closed ThSGM closed 1 year ago

ThSGM commented 3 years ago

I prefer to keep my tmux configuration files in .config/tmux according to the XDG Directory Specifications. Is there an easy way to do this?

I suppose that we could go and replace all the hardcoded ~/.tmux.conf references in the .tmux.conf file but I was hoping for a more elegant way.

gpakosz commented 3 years ago

Hello @ThSGM 👋

I explored the idea of having the location of .tmux.conf and .tmux.conf.local configurable in the gh200-gh221 branch.

To use it you would need to somewhat launch tmux the following way

$ TMUX_CONF=/foo/bar/tmux.conf TMUX_CONF_LOCAL=/foo/bar/tmux.conf.local tmux -f /foo/bar/tmux.conf

or

$ TMUX_CONF=/foo/bar/tmux.conf TMUX_CONF_LOCAL=/foo/bar/tmux.conf.local sh -c 'tmux -f $TMUX_CONF'

The branch is way behind master. I wasn't sure I would ever merge it but I see tmux 3.2 is going to try $XDG_CONFIG_HOME/tmux/tmux.conf as well as ~/.config/tmux/tmux.conf.

I'm still not sure how I'll handle this.

In the meantime, your best bet is to symlink ~/.tmux.conf.

elisiano commented 3 years ago

By no mean an ideal solution but why not put the files where you prefer and create symlinks where this repo expects them?

gpakosz commented 3 years ago

@elisiano indeed the current solution is to clone the repository anywhere you want provided you:

ThSGM commented 3 years ago

By no mean an ideal solution but why not put the files where you prefer and create symlinks where this repo expects them?

@elisiano and @gpakosz

Indeed this is what I currently do. It is just an effort to try to clean up the number of files in my home directory. With the XDG Specifications, it makes sense to shuffle everything into .config/tmux though.

gpakosz commented 3 years ago

With the XDG Specifications, it makes sense to shuffle everything into .config/tmux though.

Well yes and no. Only tmux 3.2 understand XDG and it's a Linux thing only

wren commented 3 years ago

@gpakosz Are you sure about that? I'm on tmux 3.1c and on a Mac, and my config is at ~/.config/tmux/tmux.conf. Everything is working as expected.

gpakosz commented 3 years ago

@wren You're right it's in 3.1c

wren commented 3 years ago

@gpakosz Ah, that makes sense. There's also a bunch of terminal apps that I use that support XDG even though I'm on a Mac.

Anyway, I have a hastily modified version of your script in my dotfiles (in order to have a custom location). I've been thinking about sending over a proper PR to add the functionality. If that's something you might be open to, I'm happy to talk through implementation details to iron something out. Do you think that's something you'd be interested in?

dycw commented 3 years ago

By no mean an ideal solution but why not put the files where you prefer and create symlinks where this repo expects them?

@elisiano I believe the overall impetus is to keep a clean home directory.

gpakosz commented 3 years ago

Hey @wren 👋

I have multiple branches in the work so PR not really welcome as it's going to create more merge burden than anything else. Thanks anyway

wren commented 3 years ago

Hey @wren 👋

I have multiple branches in the work so PR not really welcome as it's going to create more merge burden than anything else. Thanks anyway

Ok, makes sense. Thanks for the response.

jhogendorn commented 3 years ago

I'd really like to see this happen as well. Happy to do a PR or whatever is appropriate to help.

charlie39 commented 2 years ago

@gpakosz i am on 3.3a and i think tmux.conf.local is only referenced from tmux.conf so if all the hard links to tmux.conf.local in tmux.conf are changed than it should work no? This is how it is working for me. as per the man page Also Using simple variables to hold file paths would be convenient.

from the man page :


     -f file       Specify an alternative configuration file.  By default, tmux loads the system configuration file
                   from /etc/tmux.conf, if present, then looks for a user configuration file at ~/.tmux.conf,
                   $XDG_CONFIG_HOME/tmux/tmux.conf or ~/.config/tmux/tmux.conf.

                   The configuration file is a set of tmux commands which are executed in sequence when the server
                   is first started.  tmux loads configuration files once when the server process has started.  The
                   source-file command may be used to load a file later.

So tmux can see configuration files under $XDG_CONFIG_HOME/tmux or ~/.config/tmux

Once that's detected source-file can be used to source the tmux.conf.local from tmux.conf.

gpakosz commented 1 year ago

Can you please try the gh-200+221+439+586 branch?

latipun7 commented 1 year ago

I have tried, but it's not picked all my local config. Keybindings and some UI is picked. Tried with default tmux.conf.local is also still broken.

sed hack = sed -i 's#\.tmux\.conf#.config/tmux/tmux.conf#g' ~/.local/share/oh-my-tmux/.tmux.conf

Default local config with sed hack: image

Default local config with that branch: image

My local config with sed hack: image

My local config with that branch: image

gpakosz commented 1 year ago

Hello @latipun7

Can you please tell me

After having switched to the gh-200+221+439+586 branch (commit 1591e944012c7883f186c26e2ef846a177d96867) and made sure .tmux.conf is unmodified, can you please make sure all tmux processes are killed, then launch tmux, and then paste the result of

$ env | grep TMUX

Thank you

latipun7 commented 1 year ago

.tmux.conf is unmodified.

❯ env | rg TMUX
TMUX=/tmp/tmux-1000/default,9781,0
TMUX_CONF=/home/latipun/.config/tmux/tmux.conf
TMUX_CONF_LOCAL=/home/latipun/.config/tmux/tmux.conf.local
TMUX_PANE=%0
TMUX_PLUGIN_MANAGER_PATH=/home/latipun/.local/share/tmux/plugins
ZSH_TMUX_CONFIG=/home/latipun/.config/tmux/tmux.conf
ZSH_TMUX_TERM=screen-256color
_ZSH_TMUX_FIXED_CONFIG=/home/latipun/.local/share/oh-my-zsh/plugins/tmux/tmux.extra.conf
gpakosz commented 1 year ago

🤔 You should see a TMUX_EXECUTABLE environment variable

gpakosz commented 1 year ago

I pushed commit 9149b2e89f718cbc019ece9526416e7d628f8c3b, can you please update and after having launched tmux, can you please paste the output of the following command?

$ cut -c3- "$TMUX_CONF" | sh -sx _apply_configuration
latipun7 commented 1 year ago

I didn't set TMUX_EXECUTABLE, my tmux bin is at default /usr/bin/tmux

❯ cut -c3- "$TMUX_CONF" | sh -sx _apply_configuration
+ :
+ set -e
+ unset GREP_OPTIONS
+ export LC_NUMERIC=C
+ LC_NUMERIC=C
+ set +H
+ set +H
+ printf ''
+ sed -E s///
+ '[' -z /tmp/tmux-1000/default,12645,0 ']'
++ printf %s /tmp/tmux-1000/default,12645,0
++ cut -d, -f1
+ TMUX_SOCKET=/tmp/tmux-1000/default
+ '[' -z '' ']'
++ lsof -a -U -Fp /tmp/tmux-1000/default
++ perl -n -e 'print if s/^p//g'
+ TMUX_PID=
++ lsof -b -w -a -d txt -p '' -Fn
++ perl -n -e 'do {print; last } if s/^n((?:.(?!dylib$|so$))+)$/\1/g'
+ TMUX_EXECUTABLE=
++ uname -s
+ _uname_s=Linux
++ tmux -V
++ '' -S /tmp/tmux-1000/default -V
++ awk '{gsub(/[^0-9.]/, "", $2); print ($2+0) * 100}'
main: line 184: : command not found
+ _tmux_version=
+ command -v pkill
+ _apply_configuration
++ tmux display -p '#{window_active}'
++ true
+ window_active=
+ '[' -z '' ']'
+ command -v perl
+ command -v sed
+ command -v awk
+ '[' -lt 240 ']'
main: line 1481: [: -lt: unary operator expected
+ command -v reattach-to-user-namespace
+ case "$_uname_s" in
+ _apply_24b
+ tmux_conf_theme_24b_colour=auto
+ _apply_theme
+ tmux_conf_24b_colour=true
+ '[' xtrue = xauto ']'
+ _is_true true
+ '[' xtrue = xtrue ']'
+ wait
+ apply_24b=true
+ '[' xtrue = xtrue ']'
+ case "$TERM" in
+ _apply_bindings
+ rm -f /tmp/log.txt
++ mktemp
+ exec
+ cfg=/tmp/tmp.4nQXu0kdKK
+ trap 'rm -f $cfg*' EXIT
+ tmux list-keys
+ '' -S /tmp/tmux-1000/default list-keys
+ grep -vF tmux.conf.local
+ grep -E 'new-window|split(-|_)window|new-session|copy-selection|copy-pipe'
main: line 184: : command not found
+ rm -f /tmp/tmp.4nQXu0kdKK
+ _apply_plugins
+ tmux_conf_update_plugins_on_launch=true
+ tmux_conf_update_plugins_on_reload=true
+ tmux_conf_uninstall_plugins_on_reload=true
+ tmux run -b 'cut -c3- "/home/latipun/.config/tmux/tmux.conf" | sh -s __apply_plugins "" "true" "true" "true"'
+ '' -S /tmp/tmux-1000/default run -b 'cut -c3- "/home/latipun/.config/tmux/tmux.conf" | sh -s __apply_plugins "" "true" "true" "true"'
main: line 184: : command not found
gpakosz commented 1 year ago

I see, it's TMUX_EXECUTABLE detection that doesnt' work

gpakosz commented 1 year ago

Do you have lsof?

latipun7 commented 1 year ago

yes I do have lsof, installed just now if it is needed for debug or something

gpakosz commented 1 year ago

If you installed it just now then that explains why it was not working before. I need to figure out what to do when lsof is not available. I'll keep you posted

latipun7 commented 1 year ago

I'm sorry, I didn't notice your full comments. I didn't update to the 9149b2e89f718cbc019ece9526416e7d628f8c3b commit yet.

After updating it, now it is works even without TMUX_EXECUTABLE set. Thank you :pray:

gpakosz commented 1 year ago

It now works because you installed lsof 🙂

latipun7 commented 1 year ago

Oh my... lol, so that's required for the config to run properly. I thought it was for debugging.

Dem right, after uninstalling lsof, the config back to broken state.

gpakosz commented 1 year ago

Can you please

TMUX_EXECUTABLE should be set to /usr/bin/tmux. If detection fails, at least the variable should contain tmux.

It that doesn't work, I'll debug more later

latipun7 commented 1 year ago

after launching tmux, the TMUX_EXECUTABLE is properly detected and set. But I noticed that the weather widget is not updated, always empty string.

My weather widget at tmux.conf.local:

# weather() {
#   curl -fsm3 'wttr.in/Godean?format=%l:+%c%t+%w+(%m+%M)\n' || printf '\n'
#   sleep 9  # 9s elapsed... still not updating
# }
gpakosz commented 1 year ago

Commit a75fdbb2da446f827a04392a767991b7d5accefc should fix custom variables.

latipun7 commented 1 year ago

Thank you, @gpakosz :tada: Now it works! I didn't notice any problem.

gpakosz commented 1 year ago

Thanks @latipun7 for the tests, appreciated 👍

I'll do more testing myself and wait for the dust to settle before merging

What's TMUX_EXECUTABLE for you btw?

latipun7 commented 1 year ago

Yeah, thank you. I'll wait for this to be merged :rocket:

Here's the complete env now (ZSH_TMUX* is from oh-my-zsh plugin):

❯ env | rg TMUX
TMUX=/tmp/tmux-1000/default,44186,0
TMUX_CONF=/home/latipun/.config/tmux/tmux.conf
TMUX_CONF_LOCAL=/home/latipun/.config/tmux/tmux.conf.local
TMUX_EXECUTABLE=/usr/bin/tmux
TMUX_PANE=%0
TMUX_PLUGIN_MANAGER_PATH=/home/latipun/.local/share/tmux/plugins
ZSH_TMUX_CONFIG=/home/latipun/.config/tmux/tmux.conf
ZSH_TMUX_TERM=screen-256color
_ZSH_TMUX_FIXED_CONFIG=/home/latipun/.local/share/oh-my-zsh/plugins/tmux/tmux.extra.conf

also, the only environment I set myself (as I remember) is only TMUX_PLUGIN_MANAGER_PATH which is I set it from tmux.conf.local