From 33c5d9a3af9f56f61657fdebc78a6f184e486fa6 Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Wed, 20 Feb 2019 12:51:26 -0700 Subject: [PATCH 1/2] Re-order private functions to make the following diff easier to read --- scripts/helpers/plugin_functions.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index cbd1b55..0593c65 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -1,20 +1,6 @@ # using @tpm_plugins is now deprecated in favor of using @plugin syntax tpm_plugins_variable_name="@tpm_plugins" -# manually expanding tilde char or `$HOME` variable. -_manual_expansion() { - local path="$1" - local expanded_tilde="${path/#\~/$HOME}" - echo "${expanded_tilde/#\$HOME/$HOME}" -} - -_tpm_path() { - local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/" - _manual_expansion "$string_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. # @@ -49,6 +35,20 @@ _sourced_files() { awk '/^[ \t]*source(-file)? +/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $2 }' } +# manually expanding tilde char or `$HOME` variable. +_manual_expansion() { + local path="$1" + local expanded_tilde="${path/#\~/$HOME}" + echo "${expanded_tilde/#\$HOME/$HOME}" +} + +_tpm_path() { + local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/" + _manual_expansion "$string_path" +} + +_CACHED_TPM_PATH="$(_tpm_path)" + # Want to be able to abort in certain cases trap "exit 1" TERM export TOP_PID=$$ From 5edba1c1d112b51706f3ba3344f84a3d7d8acb67 Mon Sep 17 00:00:00 2001 From: Raul E Rangel Date: Wed, 20 Feb 2019 12:52:58 -0700 Subject: [PATCH 2/2] Use the running tmux server to get @plugins or start a new server I normally start my tmux server with a script because I don't have a .tmux.config. i.e., tmux set -g @plugin 'tmux-plugins/tmux-resurrect' \; ... This change makes it so that @plugins is sourced from the currently running tmux server instead of spinning up a new one. This also means that we no longer need to manually parse the configs. There was also a problem that _tpm_path would not work correctly if using $XDG_CONFIG_HOME/tmux/tmux.conf because tmux by default doesn't check that path. I tested this with both inside and outside tmux by running ./tpm/bin/install_plugin --- scripts/helpers/plugin_functions.sh | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index 0593c65..8eb7d36 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -18,21 +18,13 @@ _get_user_tmux_conf() { fi } -_tmux_conf_contents() { - 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 - cat $(_manual_expansion "$file") 2>/dev/null - done +_exec_tmux() { + local OPTS=() + if [[ -z "$TMUX" ]]; then + OPTS+=(-f "$(_get_user_tmux_conf)" start-server \;) fi -} -# return files sourced from tmux config files -_sourced_files() { - _tmux_conf_contents | - awk '/^[ \t]*source(-file)? +/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $2 }' + tmux "${OPTS[@]}" "${@}" } # manually expanding tilde char or `$HOME` variable. @@ -43,7 +35,7 @@ _manual_expansion() { } _tpm_path() { - local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/" + local string_path="$(_exec_tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/" _manual_expansion "$string_path" } @@ -69,12 +61,9 @@ tpm_path() { } tpm_plugins_list_helper() { - # lists plugins from @tpm_plugins option - echo "$(tmux start-server\; show-option -gqv "$tpm_plugins_variable_name")" - - # read set -g @plugin "tmux-plugins/tmux-example-plugin" entries - _tmux_conf_contents "full" | - awk '/^[ \t]*set(-option)? +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }' + # lists plugins from @tpm_plugins option and @plugins + _exec_tmux show-option -gqv "$tpm_plugins_variable_name" \; \ + show-option -gqv "@plugin" \; } # Allowed plugin name formats: