Reputation: 11
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)'
Upvotes: 1
Views: 1593
Reputation: 3691
tmux display-message -p "#{config_files}"
/pathto/config/tmux/config
see man tmux
> FORMATS
:
config_files List of configuration files loaded
Upvotes: 1
Reputation:
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.
Upvotes: 1