Skip to content

Commit 2c4a2df

Browse files
committed
Add flexible tmux configuration load function.
Add function `_get_user_tmux_conf` to helper script `plugin_functions`. Function is searching for the users tmux configuration on multiple places by a prioritized order. The response is used within`_tmux_conf_contents` to read in the content as normally. Add new environment variable `TMUX_PLUGIN_MANAGER_CONFIG_LOCATION` which is optional to be defined. If so it has the highest priority to be loaded, despite if the file exist or not. XDG directory support has been added as well by the second priority location at `$XDG_CONFIG_HOME/tmux/tmux.conf`.
1 parent 95f7833 commit 2c4a2df

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

scripts/helpers/plugin_functions.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,30 @@ _tpm_path() {
1515

1616
_CACHED_TPM_PATH="$(_tpm_path)"
1717

18+
# Get the absolute path to the users configuration file of TMux.
19+
# This includes a prioritized search on different locations.
20+
#
21+
_get_user_tmux_conf() {
22+
# Define the different possible locations.
23+
custom_location="$TMUX_PLUGIN_MANAGER_CONFIG_LOCATION"
24+
xdg_location="$XDG_CONFIG_HOME/tmux/tmux.conf"
25+
default_location="$HOME/.tmux.conf"
26+
27+
# Search for the correct configuration file by priority.
28+
if [ -n "$custom_location" ]; then
29+
echo "$custom_location"
30+
31+
elif [ -f "$xdg_location" ]; then
32+
echo "$xdg_location"
33+
34+
else
35+
echo "$default_location"
36+
fi
37+
}
38+
1839
_tmux_conf_contents() {
19-
cat /etc/tmux.conf ~/.tmux.conf 2>/dev/null
40+
user_config=$(_get_user_tmux_conf)
41+
cat /etc/tmux.conf "$user_config" 2>/dev/null
2042
if [ "$1" == "full" ]; then # also output content from sourced files
2143
local file
2244
for file in $(_sourced_files); do

0 commit comments

Comments
 (0)