From aeb196db5c13161defbac64314d47ca346b34826 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Sun, 18 Oct 2020 13:13:08 +0200 Subject: [PATCH] Fix issue with automatic tpm install Fixes #99 --- bin/install_plugins | 3 +++ scripts/helpers/tpm_path.sh | 30 ++++++++++++++++++++++++++++++ tpm | 29 +---------------------------- 3 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 scripts/helpers/tpm_path.sh diff --git a/bin/install_plugins b/bin/install_plugins index c66b15b..2c1b434 100755 --- a/bin/install_plugins +++ b/bin/install_plugins @@ -8,7 +8,10 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPTS_DIR="$CURRENT_DIR/../scripts" +source "$SCRIPTS_DIR/helpers/tpm_path.sh" + main() { + set_tpm_path "$SCRIPTS_DIR/install_plugins.sh" # has correct exit code } main diff --git a/scripts/helpers/tpm_path.sh b/scripts/helpers/tpm_path.sh new file mode 100644 index 0000000..7783306 --- /dev/null +++ b/scripts/helpers/tpm_path.sh @@ -0,0 +1,30 @@ +CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +source "$CURRENT_DIR/../variables.sh" + +tpm_path_set() { + tmux show-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" >/dev/null 2>&1 +} + +# Check if configuration file exists at an XDG-compatible location, if so use +# that directory for TMUX_PLUGIN_MANAGER_PATH. Otherwise use $DEFAULT_TPM_PATH. +set_default_tpm_path() { + local xdg_tmux_path="${XDG_CONFIG_HOME:-$HOME/.config}/tmux" + local tpm_path="$DEFAULT_TPM_PATH" + + if [ -f "$xdg_tmux_path/tmux.conf" ]; then + tpm_path="$xdg_tmux_path/plugins/" + fi + + tmux set-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" "$tpm_path" +} + +# Ensures TMUX_PLUGIN_MANAGER_PATH global env variable is set. +# +# Put this in `.tmux.conf` to override the default: +# `set-environment -g TMUX_PLUGIN_MANAGER_PATH "/some/other/path/"` +set_tpm_path() { + if ! tpm_path_set; then + set_default_tpm_path + fi +} diff --git a/tpm b/tpm index 7ad4b99..c44896d 100755 --- a/tpm +++ b/tpm @@ -4,7 +4,7 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" BINDINGS_DIR="$CURRENT_DIR/bindings" SCRIPTS_DIR="$CURRENT_DIR/scripts" -source "$SCRIPTS_DIR/variables.sh" +source "$SCRIPTS_DIR/helpers/tpm_path.sh" get_tmux_option() { local option="$1" @@ -17,33 +17,6 @@ get_tmux_option() { fi } -tpm_path_set() { - tmux show-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" >/dev/null 2>&1 -} - -# Check if configuration file exists at an XDG-compatible location, if so use -# that directory for TMUX_PLUGIN_MANAGER_PATH. Otherwise use $DEFAULT_TPM_PATH. -set_default_tpm_path() { - local xdg_tmux_path="${XDG_CONFIG_HOME:-$HOME/.config}/tmux" - local tpm_path="$DEFAULT_TPM_PATH" - - if [ -f "$xdg_tmux_path/tmux.conf" ]; then - tpm_path="$xdg_tmux_path/plugins/" - fi - - tmux set-environment -g "$DEFAULT_TPM_ENV_VAR_NAME" "$tpm_path" -} - -# Ensures TMUX_PLUGIN_MANAGER_PATH global env variable is set. -# -# Put this in `.tmux.conf` to override the default: -# `set-environment -g TMUX_PLUGIN_MANAGER_PATH "/some/other/path/"` -set_tpm_path() { - if ! tpm_path_set; then - set_default_tpm_path - fi -} - # 1. Fetches plugin names from `@plugin` variables # 2. Creates full plugin path # 3. Sources all *.tmux files from each of the plugin directories