From 9be7f975e96fa9ead2333f51ce9ca5e8eef2f636 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Mon, 3 Aug 2015 17:40:50 +0200 Subject: [PATCH] Move all helpers to 'helpers/' dir --- bindings/update_plugins | 6 ++-- scripts/clean_plugins.sh | 7 +++-- .../plugin_functions.sh} | 30 ++++--------------- scripts/helpers/utility.sh | 17 +++++++++++ scripts/install_plugins.sh | 7 +++-- scripts/source_plugins.sh | 7 +++-- scripts/update_plugin.sh | 11 +++---- 7 files changed, 43 insertions(+), 42 deletions(-) rename scripts/{shared_functions.sh => helpers/plugin_functions.sh} (76%) create mode 100644 scripts/helpers/utility.sh diff --git a/bindings/update_plugins b/bindings/update_plugins index 3ee16ec..28cc281 100755 --- a/bindings/update_plugins +++ b/bindings/update_plugins @@ -11,19 +11,19 @@ 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/plugin_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)" + local plugins="$(tpm_plugins_list_helper)" tmux_echo "Installed plugins:" tmux_echo "" for plugin in $plugins; do # displaying only installed plugins if plugin_already_installed "$plugin"; then - local plugin_name="$(shared_plugin_name "$plugin")" + local plugin_name="$(plugin_name_helper "$plugin")" tmux_echo " $plugin_name" fi done diff --git a/scripts/clean_plugins.sh b/scripts/clean_plugins.sh index 6716271..a025524 100755 --- a/scripts/clean_plugins.sh +++ b/scripts/clean_plugins.sh @@ -3,7 +3,8 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" HELPERS_DIR="$CURRENT_DIR/helpers" -source "$CURRENT_DIR/shared_functions.sh" +source "$HELPERS_DIR/plugin_functions.sh" +source "$HELPERS_DIR/utility.sh" if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions source "$HELPERS_DIR/tmux_echo_functions.sh" @@ -13,11 +14,11 @@ fi clean_plugins() { local plugins plugin plugin_directory - plugins="$(shared_get_tpm_plugins_list)" + plugins="$(tpm_plugins_list_helper)" for plugin_directory in "$(tpm_path)"/*; do [ -d "${plugin_directory}" ] || continue - plugin="$(shared_plugin_name "${plugin_directory}")" + plugin="$(plugin_name_helper "${plugin_directory}")" case "${plugins}" in *"${plugin}"*) : ;; *) diff --git a/scripts/shared_functions.sh b/scripts/helpers/plugin_functions.sh similarity index 76% rename from scripts/shared_functions.sh rename to scripts/helpers/plugin_functions.sh index 4e429b1..4c34412 100644 --- a/scripts/shared_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -1,5 +1,3 @@ -# shared functions and constants - # using @tpm_plugins is now deprecated in favor of using @plugin syntax tpm_plugins_variable_name="@tpm_plugins" @@ -20,7 +18,7 @@ _tmux_conf_contents() { cat /etc/tmux.conf ~/.tmux.conf 2>/dev/null } -shared_get_tpm_plugins_list() { +tpm_plugins_list_helper() { # DEPRECATED: lists plugins from @tpm_plugins option echo "$(tmux start-server\; show-option -gqv "$tpm_plugins_variable_name")" @@ -32,7 +30,7 @@ shared_get_tpm_plugins_list() { # Allowed plugin name formats: # 1. "git://github.com/user/plugin_name.git" # 2. "user/plugin_name" -shared_plugin_name() { +plugin_name_helper() { local plugin="$1" # get only the part after the last slash, e.g. "plugin_name.git" local plugin_basename="$(basename "$plugin")" @@ -41,34 +39,16 @@ shared_plugin_name() { echo "$plugin_name" } -shared_plugin_path() { +plugin_path_helper() { local plugin="$1" - local plugin_name="$(shared_plugin_name "$plugin")" + local plugin_name="$(plugin_name_helper "$plugin")" echo "$(tpm_path)${plugin_name}/" } plugin_already_installed() { local plugin="$1" - local plugin_path="$(shared_plugin_path "$plugin")" + local plugin_path="$(plugin_path_helper "$plugin")" [ -d "$plugin_path" ] && cd "$plugin_path" && git remote >/dev/null 2>&1 } - -ensure_tpm_path_exists() { - mkdir -p "$(tpm_path)" -} - -fail_helper() { - local message="$1" - echo "$message" >&2 - FAIL="true" -} - -exit_value_helper() { - if [ "$FAIL" == "true" ]; then - exit 1 - else - exit 0 - fi -} diff --git a/scripts/helpers/utility.sh b/scripts/helpers/utility.sh new file mode 100644 index 0000000..de6eb35 --- /dev/null +++ b/scripts/helpers/utility.sh @@ -0,0 +1,17 @@ +ensure_tpm_path_exists() { + mkdir -p "$(tpm_path)" +} + +fail_helper() { + local message="$1" + echo "$message" >&2 + FAIL="true" +} + +exit_value_helper() { + if [ "$FAIL" == "true" ]; then + exit 1 + else + exit 0 + fi +} diff --git a/scripts/install_plugins.sh b/scripts/install_plugins.sh index f143940..7958ab5 100755 --- a/scripts/install_plugins.sh +++ b/scripts/install_plugins.sh @@ -3,7 +3,8 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" HELPERS_DIR="$CURRENT_DIR/helpers" -source "$CURRENT_DIR/shared_functions.sh" +source "$HELPERS_DIR/plugin_functions.sh" +source "$HELPERS_DIR/utility.sh" if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions source "$HELPERS_DIR/tmux_echo_functions.sh" @@ -29,7 +30,7 @@ clone_plugin() { # clone plugin and produce output install_plugin() { local plugin="$1" - local plugin_name="$(shared_plugin_name "$plugin")" + local plugin_name="$(plugin_name_helper "$plugin")" if plugin_already_installed "$plugin"; then echo_ok "Already installed \"$plugin_name\"" @@ -42,7 +43,7 @@ install_plugin() { } install_plugins() { - local plugins="$(shared_get_tpm_plugins_list)" + local plugins="$(tpm_plugins_list_helper)" for plugin in $plugins; do install_plugin "$plugin" done diff --git a/scripts/source_plugins.sh b/scripts/source_plugins.sh index 8a6715b..bb79c26 100755 --- a/scripts/source_plugins.sh +++ b/scripts/source_plugins.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +HELPERS_DIR="$CURRENT_DIR/helpers" -source "$CURRENT_DIR/shared_functions.sh" +source "$HELPERS_DIR/plugin_functions.sh" plugin_dir_exists() { [ -d "$1" ] @@ -27,9 +28,9 @@ silently_source_all_tmux_files() { source_plugins() { local plugin plugin_path - local plugins="$(shared_get_tpm_plugins_list)" + local plugins="$(tpm_plugins_list_helper)" for plugin in $plugins; do - plugin_path="$(shared_plugin_path "$plugin")" + plugin_path="$(plugin_path_helper "$plugin")" silently_source_all_tmux_files "$plugin_path" done } diff --git a/scripts/update_plugin.sh b/scripts/update_plugin.sh index ec47614..d923d83 100755 --- a/scripts/update_plugin.sh +++ b/scripts/update_plugin.sh @@ -5,7 +5,8 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" HELPERS_DIR="$CURRENT_DIR/helpers" -source "$CURRENT_DIR/shared_functions.sh" +source "$HELPERS_DIR/plugin_functions.sh" +source "$HELPERS_DIR/utility.sh" if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions source "$HELPERS_DIR/tmux_echo_functions.sh" @@ -18,7 +19,7 @@ shift pull_changes() { local plugin="$1" - local plugin_path="$(shared_plugin_path "$plugin")" + local plugin_path="$(plugin_path_helper "$plugin")" cd "$plugin_path" && GIT_TERMINAL_PROMPT=0 git pull && GIT_TERMINAL_PROMPT=0 git submodule update --init --recursive @@ -35,9 +36,9 @@ update() { update_all() { echo_ok "Updating all plugins!" echo_ok "" - local plugins="$(shared_get_tpm_plugins_list)" + local plugins="$(tpm_plugins_list_helper)" for plugin in $plugins; do - local plugin_name="$(shared_plugin_name "$plugin")" + local plugin_name="$(plugin_name_helper "$plugin")" # updating only installed plugins if plugin_already_installed "$plugin_name"; then update "$plugin_name" @@ -48,7 +49,7 @@ update_all() { update_plugins() { local plugins="$*" for plugin in $plugins; do - local plugin_name="$(shared_plugin_name "$plugin")" + local plugin_name="$(plugin_name_helper "$plugin")" if plugin_already_installed "$plugin_name"; then update "$plugin_name" else