'Get absolut path to tmux.conf in tmux configuration file
I'm desperately trying to extract the absolute path of the tmux.conf file (which is a symbolic link) within the file itself. Usually one can achieve this easily in bash with:
file_dir=$(dirname $(realpath -f $0))
But I'm not sure how to achieve this in tmux.conf.
Some background: I have a repo which holds my config of tmux I use on several machines. All I want to do is clone the repo set the symbolic link and the tmux.conf figures out where the repo and all the necessary files are located. But therefore I need to have knowledge about the absolute path of the symbolic link. I don't want to add anything to bashrc or create a other script which triggers the tmux.conf.
Anyone suggestions how to achieve this?
As @Nicholas Marriott pointed out this works like charm! Thanks.
run -b 'tmux set-env -g TMUX_PLUGIN_MANAGER_PATH "$(dirname $(realpath -f $HOME/.tmux.conf))/plugins/"'
ran -b '$(dirname $(realpath -f $HOME/.tmux.conf)/plugins/tpm/tpm)'
Solution 1:[1]
There is no way to get the path of the config file like $0
but if you know its location and just want to know where it points you can do, for example:
run 'tmux set -g @conf_dir "$(dirname $(realpath -f ~/.tmux.conf))"'
Then use #{@conf_dir}
.
But note that source-file
does not expand formats, so you can't just do source-file "#{@conf_dir}/*.conf"
- you will have to use run-shell
which does, for example:
run 'tmux source "#{@conf_dir}/*.conf"'
Also because you are setting a user option it will not be available until the command is run, so not at parse time.
Solution 2:[2]
tmux display-message -p "#{config_files}"
/pathto/config/tmux/config
see man tmux
> FORMATS
:
config_files List of configuration files loaded
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Nicholas Marriott |
Solution 2 | timotheecour |