Helper functions refactoring
This commit is contained in:
parent
eab403b6d8
commit
5adc9a987f
11 changed files with 59 additions and 97 deletions
|
@ -5,8 +5,10 @@
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
|
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() {
|
main() {
|
||||||
reload_tmux_environment
|
reload_tmux_environment
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
|
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() {
|
main() {
|
||||||
reload_tmux_environment
|
reload_tmux_environment
|
||||||
|
|
|
@ -9,8 +9,11 @@
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
|
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
|
||||||
|
HELPERS_DIR="$SCRIPTS_DIR/helpers"
|
||||||
|
|
||||||
source "$SCRIPTS_DIR/shared_functions.sh"
|
source "$SCRIPTS_DIR/shared_functions.sh"
|
||||||
|
source "$HELPERS_DIR/tmux_echo_functions.sh"
|
||||||
|
source "$HELPERS_DIR/tmux_utils.sh"
|
||||||
|
|
||||||
display_plugin_update_list() {
|
display_plugin_update_list() {
|
||||||
local plugins="$(shared_get_tpm_plugins_list)"
|
local plugins="$(shared_get_tpm_plugins_list)"
|
||||||
|
|
|
@ -1,34 +1,14 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
HELPERS_DIR="$CURRENT_DIR/helpers"
|
||||||
|
|
||||||
source "$CURRENT_DIR/shared_functions.sh"
|
source "$CURRENT_DIR/shared_functions.sh"
|
||||||
|
|
||||||
TMUX_ECHO_FLAG="$1"
|
if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions
|
||||||
|
source "$HELPERS_DIR/tmux_echo_functions.sh"
|
||||||
# True if invoked as tmux mapping or tmux command,
|
else # shell output functions
|
||||||
# false if invoked via command line wrapper from `bin/` directory.
|
source "$HELPERS_DIR/shell_echo_functions.sh"
|
||||||
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 "$*"
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
clean_plugins() {
|
clean_plugins() {
|
||||||
|
|
7
scripts/helpers/shell_echo_functions.sh
Normal file
7
scripts/helpers/shell_echo_functions.sh
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
echo_ok() {
|
||||||
|
echo "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
echo_err() {
|
||||||
|
fail_helper "$*"
|
||||||
|
}
|
19
scripts/helpers/tmux_echo_functions.sh
Normal file
19
scripts/helpers/tmux_echo_functions.sh
Normal file
|
@ -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."
|
||||||
|
}
|
3
scripts/helpers/tmux_utils.sh
Normal file
3
scripts/helpers/tmux_utils.sh
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
reload_tmux_environment() {
|
||||||
|
tmux source-file ~/.tmux.conf >/dev/null 2>&1
|
||||||
|
}
|
|
@ -1,34 +1,14 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
HELPERS_DIR="$CURRENT_DIR/helpers"
|
||||||
|
|
||||||
source "$CURRENT_DIR/shared_functions.sh"
|
source "$CURRENT_DIR/shared_functions.sh"
|
||||||
|
|
||||||
TMUX_ECHO_FLAG="$1"
|
if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions
|
||||||
|
source "$HELPERS_DIR/tmux_echo_functions.sh"
|
||||||
# True if invoked as tmux mapping or tmux command,
|
else # shell output functions
|
||||||
# false if invoked via command line wrapper from `bin/` directory.
|
source "$HELPERS_DIR/shell_echo_functions.sh"
|
||||||
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 "$*"
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
clone() {
|
clone() {
|
||||||
|
|
|
@ -43,17 +43,6 @@ shared_plugin_path() {
|
||||||
echo "${SHARED_TPM_PATH}${plugin_name}/"
|
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() {
|
plugin_already_installed() {
|
||||||
local plugin="$1"
|
local plugin="$1"
|
||||||
local plugin_path="$(shared_plugin_path "$plugin")"
|
local plugin_path="$(shared_plugin_path "$plugin")"
|
||||||
|
@ -62,13 +51,6 @@ plugin_already_installed() {
|
||||||
git remote >/dev/null 2>&1
|
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() {
|
ensure_tpm_path_exists() {
|
||||||
mkdir -p "$SHARED_TPM_PATH"
|
mkdir -p "$SHARED_TPM_PATH"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,37 +3,19 @@
|
||||||
# this script handles core logic of updating plugins
|
# this script handles core logic of updating plugins
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
HELPERS_DIR="$CURRENT_DIR/helpers"
|
||||||
|
|
||||||
source "$CURRENT_DIR/shared_functions.sh"
|
source "$CURRENT_DIR/shared_functions.sh"
|
||||||
|
|
||||||
TMUX_ECHO_FLAG="$1"
|
if [ "$1" == "--tmux-echo" ]; then # tmux-specific echo functions
|
||||||
shift
|
source "$HELPERS_DIR/tmux_echo_functions.sh"
|
||||||
|
else # shell output functions
|
||||||
# True if invoked as tmux mapping or tmux command,
|
source "$HELPERS_DIR/shell_echo_functions.sh"
|
||||||
# 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 "$*"
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# from now on ignore first script argument
|
||||||
|
shift
|
||||||
|
|
||||||
pull_changes() {
|
pull_changes() {
|
||||||
local plugin="$1"
|
local plugin="$1"
|
||||||
local plugin_path="$(shared_plugin_path "$plugin")"
|
local plugin_path="$(shared_plugin_path "$plugin")"
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
HELPERS_DIR="$CURRENT_DIR/helpers"
|
||||||
|
|
||||||
if [ $# -eq 0 ]; then
|
if [ $# -eq 0 ]; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
source "$CURRENT_DIR/shared_functions.sh"
|
source "$HELPERS_DIR/tmux_echo_functions.sh"
|
||||||
|
source "$HELPERS_DIR/tmux_utils.sh"
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
"$CURRENT_DIR/update_plugin.sh" --tmux-echo "$*"
|
"$CURRENT_DIR/update_plugin.sh" --tmux-echo "$*"
|
||||||
|
|
Loading…
Reference in a new issue