Move all helpers to 'helpers/' dir

This commit is contained in:
Bruno Sutic 2015-08-03 17:40:50 +02:00
parent 0e9b64ffc4
commit 9be7f975e9
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
7 changed files with 43 additions and 42 deletions

View File

@ -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

View File

@ -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}"*) : ;;
*)

View File

@ -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
}

View File

@ -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
}

View File

@ -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

View File

@ -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
}

View File

@ -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