update_plugin script
This commit is contained in:
parent
3a5f56f10d
commit
3af756d836
4 changed files with 99 additions and 34 deletions
|
@ -26,14 +26,6 @@ clone_plugin() {
|
||||||
clone "https://github.com/$plugin"
|
clone "https://github.com/$plugin"
|
||||||
}
|
}
|
||||||
|
|
||||||
pull_changes() {
|
|
||||||
local plugin=$1
|
|
||||||
local plugin_path=$(shared_plugin_path "$plugin")
|
|
||||||
cd $plugin_path &&
|
|
||||||
git pull &&
|
|
||||||
git submodule update --init --recursive
|
|
||||||
}
|
|
||||||
|
|
||||||
# pull new changes or clone plugin
|
# pull new changes or clone plugin
|
||||||
install_plugin() {
|
install_plugin() {
|
||||||
local plugin=$1
|
local plugin=$1
|
||||||
|
|
|
@ -16,12 +16,12 @@ shared_get_tpm_plugins_list() {
|
||||||
# 1. "git://github.com/user/plugin_name.git"
|
# 1. "git://github.com/user/plugin_name.git"
|
||||||
# 2. "user/plugin_name"
|
# 2. "user/plugin_name"
|
||||||
shared_plugin_name() {
|
shared_plugin_name() {
|
||||||
local plugin=$1
|
local plugin="$1"
|
||||||
# get only the part after the last slash, e.g. "plugin_name.git"
|
# get only the part after the last slash, e.g. "plugin_name.git"
|
||||||
local plugin_basename=$(basename "$plugin")
|
local plugin_basename="$(basename "$plugin")"
|
||||||
# remove ".git" extension (if it exists) to get only "plugin_name"
|
# remove ".git" extension (if it exists) to get only "plugin_name"
|
||||||
local plugin_name=${plugin_basename%.git}
|
local plugin_name="${plugin_basename%.git}"
|
||||||
echo $plugin_name
|
echo "$plugin_name"
|
||||||
}
|
}
|
||||||
|
|
||||||
shared_plugin_path() {
|
shared_plugin_path() {
|
||||||
|
@ -42,8 +42,40 @@ reload_tmux_environment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
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")"
|
||||||
cd $plugin_path &&
|
cd "$plugin_path" &&
|
||||||
git remote >/dev/null 2>&1
|
git remote >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
end_message() {
|
||||||
|
echo_message ""
|
||||||
|
echo_message "TMUX environment reloaded."
|
||||||
|
echo_message ""
|
||||||
|
echo_message "Done, press ENTER to continue."
|
||||||
|
}
|
||||||
|
|
||||||
|
# Ensures a message is displayed for 5 seconds in tmux prompt.
|
||||||
|
# Does not override the 'display-time' tmux option.
|
||||||
|
display_message() {
|
||||||
|
local message="$1"
|
||||||
|
|
||||||
|
# display_duration defaults to 5 seconds, if not passed as an argument
|
||||||
|
if [ "$#" -eq 2 ]; then
|
||||||
|
local display_duration="$2"
|
||||||
|
else
|
||||||
|
local display_duration="5000"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# saves user-set 'display-time' option
|
||||||
|
local saved_display_time=$(get_tmux_option "display-time" "750")
|
||||||
|
|
||||||
|
# sets message display time to 5 seconds
|
||||||
|
tmux set-option -gq display-time "$display_duration"
|
||||||
|
|
||||||
|
# displays message
|
||||||
|
tmux display-message "$message"
|
||||||
|
|
||||||
|
# restores original 'display-time' value
|
||||||
|
tmux set-option -gq display-time "$saved_display_time"
|
||||||
|
}
|
||||||
|
|
|
@ -1,34 +1,74 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# when invoked with `prefix + U` this script:
|
|
||||||
# - shows a list of installed plugins
|
|
||||||
# - starts a prompt to enter the name of the plugin that will be updated
|
|
||||||
|
|
||||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
source "$CURRENT_DIR/shared_functions.sh"
|
source "$CURRENT_DIR/shared_functions.sh"
|
||||||
|
|
||||||
display_plugin_update_list() {
|
empty() {
|
||||||
|
[ -z "$1" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
if_all() {
|
||||||
|
[ "$1" == "all" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
cancel() {
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
pull_changes() {
|
||||||
|
local plugin="$1"
|
||||||
|
local plugin_path=$(shared_plugin_path "$plugin")
|
||||||
|
cd $plugin_path &&
|
||||||
|
git pull &&
|
||||||
|
git submodule update --init --recursive
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
local plugin="$1"
|
||||||
|
echo_message "Updating \"$plugin\""
|
||||||
|
$(pull_changes "$plugin" > /dev/null 2>&1) &&
|
||||||
|
echo_message " \"$plugin\" update success" ||
|
||||||
|
echo_message " \"$plugin\" update fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
update_all() {
|
||||||
local plugins="$(shared_get_tpm_plugins_list)"
|
local plugins="$(shared_get_tpm_plugins_list)"
|
||||||
for plugin in $plugins; do
|
for plugin in $plugins; do
|
||||||
# displaying only installed plugins
|
local plugin_name="$(shared_plugin_name "$plugin")"
|
||||||
if plugin_already_cloned "$plugin"; then
|
# updating only installed plugins
|
||||||
echo_message "$plugin"
|
if plugin_already_installed "$plugin_name"; then
|
||||||
|
update "$plugin_name"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
update_plugin_prompt() {
|
handle_plugin_update() {
|
||||||
tmux command-prompt -p 'plugin update:' " \
|
local arg="$1"
|
||||||
send-keys C-m; \
|
|
||||||
run-shell '$CURRENT_DIR/update_plugin.sh %1'"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if empty "$arg"; then
|
||||||
|
cancel
|
||||||
|
|
||||||
|
elif if_all "$arg"; then
|
||||||
|
echo_message "Updating all plugins!"
|
||||||
|
echo_message ""
|
||||||
|
update_all
|
||||||
|
|
||||||
|
elif plugin_already_installed "$arg"; then
|
||||||
|
update "$arg"
|
||||||
|
|
||||||
|
else
|
||||||
|
display_message "It seems this plugin is not installed: $arg"
|
||||||
|
cancel
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
reload_tmux_environment
|
local arg="$1"
|
||||||
shared_set_tpm_path_constant
|
shared_set_tpm_path_constant
|
||||||
display_plugin_update_list
|
handle_plugin_update "$arg"
|
||||||
update_plugin_prompt
|
reload_tmux_environment
|
||||||
|
end_message
|
||||||
}
|
}
|
||||||
main
|
main "$1"
|
||||||
|
|
|
@ -16,13 +16,14 @@ display_plugin_update_list() {
|
||||||
for plugin in $plugins; do
|
for plugin in $plugins; do
|
||||||
# displaying only installed plugins
|
# displaying only installed plugins
|
||||||
if plugin_already_installed "$plugin"; then
|
if plugin_already_installed "$plugin"; then
|
||||||
echo_message " $plugin"
|
local plugin_name="$(shared_plugin_name "$plugin")"
|
||||||
|
echo_message " $plugin_name"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
echo_message ""
|
echo_message ""
|
||||||
echo_message "Type (full) plugin name to update it."
|
echo_message "Type (full) plugin name to update it."
|
||||||
echo_message "* - updates all."
|
echo_message "Type \"all\" to update all plugins."
|
||||||
echo_message ""
|
echo_message ""
|
||||||
echo_message "ENTER - cancels"
|
echo_message "ENTER - cancels"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue