Enable installing plugins via cli executable

This commit is contained in:
Bruno Sutic 2015-07-29 23:36:49 +02:00
parent a51fb24f62
commit 40ba8e58dc
No known key found for this signature in database
GPG Key ID: 66D96E4F2F7EF26C
5 changed files with 77 additions and 16 deletions

9
bin/install_plugins Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
main() {
"$SCRIPTS_DIR/install_plugins.sh" # has correct exit code
}
main

14
bindings/install_plugins Executable file
View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SCRIPTS_DIR="$CURRENT_DIR/../scripts"
source "$SCRIPTS_DIR/shared_functions.sh"
main() {
reload_tmux_environment
"$SCRIPTS_DIR/install_plugins.sh" --tmux-echo >/dev/null 2>&1
reload_tmux_environment
end_message
}
main

View File

@ -4,9 +4,36 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
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() {
echo_message "$*"
}
echo_err() {
echo_message "$*"
}
else
echo_ok() {
echo "$*"
}
echo_err() {
fail_helper "$*"
}
fi
clone() {
local plugin=$1
cd $SHARED_TPM_PATH &&
local plugin="$1"
cd "$SHARED_TPM_PATH" &&
GIT_TERMINAL_PROMPT=0 git clone --recursive $plugin
}
@ -14,25 +41,23 @@ clone() {
# 1. plugin name directly - works if it's a valid git url
# 2. expands the plugin name to point to a github repo and tries cloning again
clone_plugin() {
local plugin=$1
local plugin="$1"
clone "$plugin" ||
clone "https://git::@github.com/$plugin"
}
# pull new changes or clone plugin
# clone plugin and produce output
install_plugin() {
local plugin="$1"
local plugin_name="$(shared_plugin_name "$plugin")"
if plugin_already_installed "$plugin"; then
# plugin is already installed
echo_message "Already installed \"$plugin_name\""
echo_ok "Already installed \"$plugin_name\""
else
# plugin wasn't cloned so far - clone it
echo_message "Installing \"$plugin_name\""
echo_ok "Installing \"$plugin_name\""
clone_plugin "$plugin" &&
echo_message " \"$plugin_name\" download success" ||
echo_message " \"$plugin_name\" download fail"
echo_ok " \"$plugin_name\" download success" ||
echo_err " \"$plugin_name\" download fail"
fi
}
@ -50,12 +75,10 @@ verify_tpm_path_permissions() {
}
main() {
reload_tmux_environment
shared_set_tpm_path_constant
ensure_tpm_path_exists
verify_tpm_path_permissions
install_plugins
reload_tmux_environment
end_message
exit_value_helper
}
main

View File

@ -6,7 +6,7 @@ SHARED_TPM_PATH=""
# sets a "global variable" for the current file
shared_set_tpm_path_constant() {
local string_path="$(tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
local string_path="$(tmux start-server\; show-environment -g TMUX_PLUGIN_MANAGER_PATH | cut -f2 -d=)/"
# manually expanding tilde or `$HOME` variable.
string_path="${string_path/#\~/$HOME}"
SHARED_TPM_PATH="${string_path/#\$HOME/$HOME}"
@ -18,7 +18,7 @@ _tmux_conf_contents() {
shared_get_tpm_plugins_list() {
# DEPRECATED: lists plugins from @tpm_plugins option
echo "$(tmux show-option -gqv "$tpm_plugins_variable_name")"
echo "$(tmux start-server\; show-option -gqv "$tpm_plugins_variable_name")"
# read set -g @plugin "tmux-plugins/tmux-example-plugin" entries
_tmux_conf_contents |
@ -96,3 +96,17 @@ display_message() {
ensure_tpm_path_exists() {
mkdir -p "$SHARED_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
}

3
tpm
View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BINDINGS_DIR="$CURRENT_DIR/bindings"
SUPPORTED_TMUX_VERSION="1.9"
@ -31,7 +32,7 @@ source_plugins() {
# prefix + alt + u - remove unused TPM plugins and reloads TMUX environment
set_tpm_key_bindings() {
local install_key=$(get_tmux_option "$install_key_option" "$default_install_key")
tmux bind-key "$install_key" run-shell "$CURRENT_DIR/scripts/install_plugins.sh >/dev/null 2>&1"
tmux bind-key "$install_key" run-shell "$BINDINGS_DIR/install_plugins"
local update_key=$(get_tmux_option "$update_key_option" "$default_update_key")
tmux bind-key "$update_key" run-shell "$CURRENT_DIR/scripts/update_plugin_prompt.sh"