diff --git a/bindings/clean_plugins b/bindings/clean_plugins index ea18752..9a0d5d7 100755 --- a/bindings/clean_plugins +++ b/bindings/clean_plugins @@ -5,8 +5,10 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPTS_DIR="$CURRENT_DIR/../scripts" +HELPERS_DIR="$SCRIPTS_DIR/helpers" -source "$SCRIPTS_DIR/shared_functions.sh" +source "$HELPERS_DIR/tmux_echo_functions.sh" +source "$HELPERS_DIR/tmux_utils.sh" main() { reload_tmux_environment diff --git a/bindings/install_plugins b/bindings/install_plugins index f92bbbc..3ade3c4 100755 --- a/bindings/install_plugins +++ b/bindings/install_plugins @@ -5,8 +5,10 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPTS_DIR="$CURRENT_DIR/../scripts" +HELPERS_DIR="$SCRIPTS_DIR/helpers" -source "$SCRIPTS_DIR/shared_functions.sh" +source "$HELPERS_DIR/tmux_echo_functions.sh" +source "$HELPERS_DIR/tmux_utils.sh" main() { reload_tmux_environment diff --git a/bindings/update_plugins b/bindings/update_plugins index f4f441f..9a3a86c 100755 --- a/bindings/update_plugins +++ b/bindings/update_plugins @@ -9,8 +9,11 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SCRIPTS_DIR="$CURRENT_DIR/../scripts" +HELPERS_DIR="$SCRIPTS_DIR/helpers" source "$SCRIPTS_DIR/shared_functions.sh" +source "$HELPERS_DIR/tmux_echo_functions.sh" +source "$HELPERS_DIR/tmux_utils.sh" display_plugin_update_list() { local plugins="$(shared_get_tpm_plugins_list)" diff --git a/scripts/clean_plugins.sh b/scripts/clean_plugins.sh index 2433ad3..4ff59f6 100755 --- a/scripts/clean_plugins.sh +++ b/scripts/clean_plugins.sh @@ -1,34 +1,14 @@ #!/usr/bin/env bash CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +HELPERS_DIR="$CURRENT_DIR/helpers" source "$CURRENT_DIR/shared_functions.sh" -TMUX_ECHO_FLAG="$1" - -# True if invoked as tmux mapping or tmux command, -# false if invoked via command line wrapper from `bin/` directory. -use_tmux_echo() { - [ "$TMUX_ECHO_FLAG" == "--tmux-echo" ] -} - -if use_tmux_echo; then - # use tmux specific echo-ing - echo_ok() { - tmux_echo "$*" - } - - echo_err() { - tmux_echo "$*" - } -else - echo_ok() { - echo "$*" - } - - echo_err() { - fail_helper "$*" - } +if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions + source "$HELPERS_DIR/tmux_echo_functions.sh" +else # shell output functions + source "$HELPERS_DIR/shell_echo_functions.sh" fi clean_plugins() { diff --git a/scripts/helpers/shell_echo_functions.sh b/scripts/helpers/shell_echo_functions.sh new file mode 100644 index 0000000..ecaa37e --- /dev/null +++ b/scripts/helpers/shell_echo_functions.sh @@ -0,0 +1,7 @@ +echo_ok() { + echo "$*" +} + +echo_err() { + fail_helper "$*" +} diff --git a/scripts/helpers/tmux_echo_functions.sh b/scripts/helpers/tmux_echo_functions.sh new file mode 100644 index 0000000..8c145b9 --- /dev/null +++ b/scripts/helpers/tmux_echo_functions.sh @@ -0,0 +1,19 @@ +tmux_echo() { + local message="$1" + tmux run-shell "echo '$message'" +} + +echo_ok() { + tmux_echo "$*" +} + +echo_err() { + tmux_echo "$*" +} + +end_message() { + tmux_echo "" + tmux_echo "TMUX environment reloaded." + tmux_echo "" + tmux_echo "Done, press ENTER to continue." +} diff --git a/scripts/helpers/tmux_utils.sh b/scripts/helpers/tmux_utils.sh new file mode 100644 index 0000000..e39946a --- /dev/null +++ b/scripts/helpers/tmux_utils.sh @@ -0,0 +1,3 @@ +reload_tmux_environment() { + tmux source-file ~/.tmux.conf >/dev/null 2>&1 +} diff --git a/scripts/install_plugins.sh b/scripts/install_plugins.sh index b1fcc87..be7cd5b 100755 --- a/scripts/install_plugins.sh +++ b/scripts/install_plugins.sh @@ -1,34 +1,14 @@ #!/usr/bin/env bash CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +HELPERS_DIR="$CURRENT_DIR/helpers" source "$CURRENT_DIR/shared_functions.sh" -TMUX_ECHO_FLAG="$1" - -# True if invoked as tmux mapping or tmux command, -# false if invoked via command line wrapper from `bin/` directory. -use_tmux_echo() { - [ "$TMUX_ECHO_FLAG" == "--tmux-echo" ] -} - -if use_tmux_echo; then - # use tmux specific echo-ing - echo_ok() { - tmux_echo "$*" - } - - echo_err() { - tmux_echo "$*" - } -else - echo_ok() { - echo "$*" - } - - echo_err() { - fail_helper "$*" - } +if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions + source "$HELPERS_DIR/tmux_echo_functions.sh" +else # shell output functions + source "$HELPERS_DIR/shell_echo_functions.sh" fi clone() { diff --git a/scripts/shared_functions.sh b/scripts/shared_functions.sh index 58b6b4b..878e73a 100644 --- a/scripts/shared_functions.sh +++ b/scripts/shared_functions.sh @@ -43,17 +43,6 @@ shared_plugin_path() { echo "${SHARED_TPM_PATH}${plugin_name}/" } -# TMUX messaging is weird. You only get a nice clean pane if you do it with -# `run-shell` command. -tmux_echo() { - local message="$1" - tmux run-shell "echo '$message'" -} - -reload_tmux_environment() { - tmux source-file ~/.tmux.conf >/dev/null 2>&1 -} - plugin_already_installed() { local plugin="$1" local plugin_path="$(shared_plugin_path "$plugin")" @@ -62,13 +51,6 @@ plugin_already_installed() { git remote >/dev/null 2>&1 } -end_message() { - tmux_echo "" - tmux_echo "TMUX environment reloaded." - tmux_echo "" - tmux_echo "Done, press ENTER to continue." -} - ensure_tpm_path_exists() { mkdir -p "$SHARED_TPM_PATH" } diff --git a/scripts/update_plugin.sh b/scripts/update_plugin.sh index a89a44a..4407102 100755 --- a/scripts/update_plugin.sh +++ b/scripts/update_plugin.sh @@ -3,37 +3,19 @@ # this script handles core logic of updating plugins CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +HELPERS_DIR="$CURRENT_DIR/helpers" source "$CURRENT_DIR/shared_functions.sh" -TMUX_ECHO_FLAG="$1" -shift - -# True if invoked as tmux mapping or tmux command, -# false if invoked via command line wrapper from `bin/` directory. -use_tmux_echo() { - [ "$TMUX_ECHO_FLAG" == "--tmux-echo" ] -} - -if use_tmux_echo; then - # use tmux specific echo-ing - echo_ok() { - tmux_echo "$*" - } - - echo_err() { - tmux_echo "$*" - } -else - echo_ok() { - echo "$*" - } - - echo_err() { - fail_helper "$*" - } +if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions + source "$HELPERS_DIR/tmux_echo_functions.sh" +else # shell output functions + source "$HELPERS_DIR/shell_echo_functions.sh" fi +# from now on ignore first script argument +shift + pull_changes() { local plugin="$1" local plugin_path="$(shared_plugin_path "$plugin")" diff --git a/scripts/update_plugin_prompt_handler.sh b/scripts/update_plugin_prompt_handler.sh index fa34992..5e1f7d9 100755 --- a/scripts/update_plugin_prompt_handler.sh +++ b/scripts/update_plugin_prompt_handler.sh @@ -1,12 +1,14 @@ #!/usr/bin/env bash CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +HELPERS_DIR="$CURRENT_DIR/helpers" if [ $# -eq 0 ]; then exit 0 fi -source "$CURRENT_DIR/shared_functions.sh" +source "$HELPERS_DIR/tmux_echo_functions.sh" +source "$HELPERS_DIR/tmux_utils.sh" main() { "$CURRENT_DIR/update_plugin.sh" --tmux-echo "$*"