From 2c4a2dfd655c13b4e15d693e2c2dba529b1d1c48 Mon Sep 17 00:00:00 2001 From: Thore Weilbier Date: Fri, 2 Nov 2018 13:07:53 +0100 Subject: [PATCH 1/3] 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`. --- scripts/helpers/plugin_functions.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index d2778d5..a757cc5 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -15,8 +15,30 @@ _tpm_path() { _CACHED_TPM_PATH="$(_tpm_path)" +# Get the absolute path to the users configuration file of TMux. +# This includes a prioritized search on different locations. +# +_get_user_tmux_conf() { + # Define the different possible locations. + custom_location="$TMUX_PLUGIN_MANAGER_CONFIG_LOCATION" + xdg_location="$XDG_CONFIG_HOME/tmux/tmux.conf" + default_location="$HOME/.tmux.conf" + + # Search for the correct configuration file by priority. + if [ -n "$custom_location" ]; then + echo "$custom_location" + + elif [ -f "$xdg_location" ]; then + echo "$xdg_location" + + else + echo "$default_location" + fi +} + _tmux_conf_contents() { - cat /etc/tmux.conf ~/.tmux.conf 2>/dev/null + user_config=$(_get_user_tmux_conf) + cat /etc/tmux.conf "$user_config" 2>/dev/null if [ "$1" == "full" ]; then # also output content from sourced files local file for file in $(_sourced_files); do From 206ded75d844915b49f388905421598b5fc2943a Mon Sep 17 00:00:00 2001 From: Thore Weilbier Date: Sun, 4 Nov 2018 11:19:28 +0100 Subject: [PATCH 2/3] Restore tabs instead of spaces for indentation. --- scripts/helpers/plugin_functions.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index a757cc5..44f8e91 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -19,25 +19,25 @@ _CACHED_TPM_PATH="$(_tpm_path)" # This includes a prioritized search on different locations. # _get_user_tmux_conf() { - # Define the different possible locations. - custom_location="$TMUX_PLUGIN_MANAGER_CONFIG_LOCATION" - xdg_location="$XDG_CONFIG_HOME/tmux/tmux.conf" - default_location="$HOME/.tmux.conf" + # Define the different possible locations. + custom_location="$TMUX_PLUGIN_MANAGER_CONFIG_LOCATION" + xdg_location="$XDG_CONFIG_HOME/tmux/tmux.conf" + default_location="$HOME/.tmux.conf" - # Search for the correct configuration file by priority. - if [ -n "$custom_location" ]; then - echo "$custom_location" + # Search for the correct configuration file by priority. + if [ -n "$custom_location" ]; then + echo "$custom_location" - elif [ -f "$xdg_location" ]; then - echo "$xdg_location" + elif [ -f "$xdg_location" ]; then + echo "$xdg_location" - else - echo "$default_location" - fi + else + echo "$default_location" + fi } _tmux_conf_contents() { - user_config=$(_get_user_tmux_conf) + user_config=$(_get_user_tmux_conf) cat /etc/tmux.conf "$user_config" 2>/dev/null if [ "$1" == "full" ]; then # also output content from sourced files local file From 0e46b92aba3938d391c21738ab39b7c0ad4fcf2f Mon Sep 17 00:00:00 2001 From: Thore Weilbier Date: Wed, 7 Nov 2018 09:31:21 +0100 Subject: [PATCH 3/3] Remove _CONFIG_LOCATION variable again. It has been decided that this feature should been removed until it will be requested. --- scripts/helpers/plugin_functions.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index 44f8e91..cbd1b55 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -20,15 +20,11 @@ _CACHED_TPM_PATH="$(_tpm_path)" # _get_user_tmux_conf() { # Define the different possible locations. - custom_location="$TMUX_PLUGIN_MANAGER_CONFIG_LOCATION" xdg_location="$XDG_CONFIG_HOME/tmux/tmux.conf" default_location="$HOME/.tmux.conf" # Search for the correct configuration file by priority. - if [ -n "$custom_location" ]; then - echo "$custom_location" - - elif [ -f "$xdg_location" ]; then + if [ -f "$xdg_location" ]; then echo "$xdg_location" else