Enable installing plugins via cli executable
This commit is contained in:
parent
a51fb24f62
commit
40ba8e58dc
5 changed files with 77 additions and 16 deletions
9
bin/install_plugins
Executable file
9
bin/install_plugins
Executable 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
14
bindings/install_plugins
Executable 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
|
|
@ -4,9 +4,36 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
source "$CURRENT_DIR/shared_functions.sh"
|
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() {
|
clone() {
|
||||||
local plugin=$1
|
local plugin="$1"
|
||||||
cd $SHARED_TPM_PATH &&
|
cd "$SHARED_TPM_PATH" &&
|
||||||
GIT_TERMINAL_PROMPT=0 git clone --recursive $plugin
|
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
|
# 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
|
# 2. expands the plugin name to point to a github repo and tries cloning again
|
||||||
clone_plugin() {
|
clone_plugin() {
|
||||||
local plugin=$1
|
local plugin="$1"
|
||||||
clone "$plugin" ||
|
clone "$plugin" ||
|
||||||
clone "https://git::@github.com/$plugin"
|
clone "https://git::@github.com/$plugin"
|
||||||
}
|
}
|
||||||
|
|
||||||
# pull new changes or clone plugin
|
# clone plugin and produce output
|
||||||
install_plugin() {
|
install_plugin() {
|
||||||
local plugin="$1"
|
local plugin="$1"
|
||||||
local plugin_name="$(shared_plugin_name "$plugin")"
|
local plugin_name="$(shared_plugin_name "$plugin")"
|
||||||
|
|
||||||
if plugin_already_installed "$plugin"; then
|
if plugin_already_installed "$plugin"; then
|
||||||
# plugin is already installed
|
echo_ok "Already installed \"$plugin_name\""
|
||||||
echo_message "Already installed \"$plugin_name\""
|
|
||||||
else
|
else
|
||||||
# plugin wasn't cloned so far - clone it
|
echo_ok "Installing \"$plugin_name\""
|
||||||
echo_message "Installing \"$plugin_name\""
|
|
||||||
clone_plugin "$plugin" &&
|
clone_plugin "$plugin" &&
|
||||||
echo_message " \"$plugin_name\" download success" ||
|
echo_ok " \"$plugin_name\" download success" ||
|
||||||
echo_message " \"$plugin_name\" download fail"
|
echo_err " \"$plugin_name\" download fail"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,12 +75,10 @@ verify_tpm_path_permissions() {
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
reload_tmux_environment
|
|
||||||
shared_set_tpm_path_constant
|
shared_set_tpm_path_constant
|
||||||
ensure_tpm_path_exists
|
ensure_tpm_path_exists
|
||||||
verify_tpm_path_permissions
|
verify_tpm_path_permissions
|
||||||
install_plugins
|
install_plugins
|
||||||
reload_tmux_environment
|
exit_value_helper
|
||||||
end_message
|
|
||||||
}
|
}
|
||||||
main
|
main
|
||||||
|
|
|
@ -6,7 +6,7 @@ SHARED_TPM_PATH=""
|
||||||
|
|
||||||
# sets a "global variable" for the current file
|
# sets a "global variable" for the current file
|
||||||
shared_set_tpm_path_constant() {
|
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.
|
# manually expanding tilde or `$HOME` variable.
|
||||||
string_path="${string_path/#\~/$HOME}"
|
string_path="${string_path/#\~/$HOME}"
|
||||||
SHARED_TPM_PATH="${string_path/#\$HOME/$HOME}"
|
SHARED_TPM_PATH="${string_path/#\$HOME/$HOME}"
|
||||||
|
@ -18,7 +18,7 @@ _tmux_conf_contents() {
|
||||||
|
|
||||||
shared_get_tpm_plugins_list() {
|
shared_get_tpm_plugins_list() {
|
||||||
# DEPRECATED: lists plugins from @tpm_plugins option
|
# 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
|
# read set -g @plugin "tmux-plugins/tmux-example-plugin" entries
|
||||||
_tmux_conf_contents |
|
_tmux_conf_contents |
|
||||||
|
@ -96,3 +96,17 @@ display_message() {
|
||||||
ensure_tpm_path_exists() {
|
ensure_tpm_path_exists() {
|
||||||
mkdir -p "$SHARED_TPM_PATH"
|
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
3
tpm
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
BINDINGS_DIR="$CURRENT_DIR/bindings"
|
||||||
|
|
||||||
SUPPORTED_TMUX_VERSION="1.9"
|
SUPPORTED_TMUX_VERSION="1.9"
|
||||||
|
|
||||||
|
@ -31,7 +32,7 @@ source_plugins() {
|
||||||
# prefix + alt + u - remove unused TPM plugins and reloads TMUX environment
|
# prefix + alt + u - remove unused TPM plugins and reloads TMUX environment
|
||||||
set_tpm_key_bindings() {
|
set_tpm_key_bindings() {
|
||||||
local install_key=$(get_tmux_option "$install_key_option" "$default_install_key")
|
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")
|
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"
|
tmux bind-key "$update_key" run-shell "$CURRENT_DIR/scripts/update_plugin_prompt.sh"
|
||||||
|
|
Loading…
Reference in a new issue