I have a file of common tmux settings I share between computers (tmux.conf.common). I'd like to be able to source this file in my tmux.conf. A way to accomplish this in bash is to have the each computer's .bashrc source the common file. Is there a way to do something analogous in tmux?
2 Answers
The .tmux.conf
format has the source-file
directive which can be used the same way. Using source
also works.
source-file /path/to/tmux.conf.common

- 71,677
- 44
- 195
- 329
-
Is there a way to use source-file with an environment path? source-file $tmuxpath/navigation.tmux – Zypps987 Nov 17 '17 at 07:01
-
I don't see why not. Tmux conf in general let's you expand environment variables. – merlin2011 Nov 17 '17 at 18:57
-
Hmm.... I'm getting the error message "/navigation.tmux" not found. I'll keep looking into this. – Zypps987 Nov 17 '17 at 22:01
-
1Nvm... I was sshd into my box with putty using the console, I made a new path variable name TMUX_DIR and it wasn't being updated for some reason.... I'm not sure why this is the case. However, when I ran a termite terminal (spawned from the console) it worked fine. Not sure why the terminal environment wasn't updating... – Zypps987 Nov 17 '17 at 22:49
A bit late but this is how I use it across my workstations and deployed servers in order to be able to share my general preferences and easily override them.
First I just moved my .tmux.conf to a tmux.common then sourced it in the now empty tmux.conf then I distributed this basic tmux.conf tmux.common to all nodes.
Since the last line in the tmux.common is run '~/.tmux/plugins/tpm/tpm' Any additional plugins need to be mentioned before the sourced file.
If needed this could easily be expanded to include more common files, for instance for making devel/test / acceptance/production systems have different colors or whatnot.
generic .tmux.conf
#
# Include commons settings, shared between systems, anything but plugin
# related stuff can come after, like overriding common bindings or settings.
# Plugin stuff needs to be specified before this!
#
source-file ~/nocloud/conf/tmux.common
workstation .tmux.conf
On my workstations I use a layout plugin, this helps to make me aware if the tmux session is local or remote, and if remote, I have to look closer at the hostname, to ensure I am doing whatever it is to the right one.
set -g @plugin "arcticicestudio/nord-tmux"
#
# Include commons settings, shared between systems, anything but plugin
# related stuff can come after, like overriding common bindings or settings.
# Plugin stuff needs to be specified before this!
#
source-file ~/Dropbox/SharedConfigs/multi-os-apps/tmux.common

- 11
- 1