1
0
Fork 0
mirror of synced 2024-11-16 22:45:35 -05:00

Helper functions refactoring

This commit is contained in:
Bruno Sutic 2015-08-03 15:12:45 +02:00
parent eab403b6d8
commit 5adc9a987f
No known key found for this signature in database
GPG key ID: 66D96E4F2F7EF26C
11 changed files with 59 additions and 97 deletions

View file

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

View file

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

View file

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

View file

@ -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() {

View file

@ -0,0 +1,7 @@
echo_ok() {
echo "$*"
}
echo_err() {
fail_helper "$*"
}

View 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."
}

View file

@ -0,0 +1,3 @@
reload_tmux_environment() {
tmux source-file ~/.tmux.conf >/dev/null 2>&1
}

View file

@ -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() {

View file

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

View file

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

View file

@ -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 "$*"