From 3a5f56f10df30f77508c23b7617f863174460921 Mon Sep 17 00:00:00 2001 From: Bruno Sutic Date: Tue, 5 Aug 2014 18:45:59 +0200 Subject: [PATCH] U key binding shows a list of installed plugins --- scripts/install_plugins.sh | 16 +----------- scripts/shared_functions.sh | 18 ++++++++++++++ scripts/update_plugin.sh | 34 ++++++++++++++++++++++++++ scripts/update_plugin_prompt.sh | 43 +++++++++++++++++++++++++++++++++ tpm | 1 + 5 files changed, 97 insertions(+), 15 deletions(-) create mode 100755 scripts/update_plugin.sh create mode 100755 scripts/update_plugin_prompt.sh diff --git a/scripts/install_plugins.sh b/scripts/install_plugins.sh index edbb76a..3222841 100755 --- a/scripts/install_plugins.sh +++ b/scripts/install_plugins.sh @@ -4,13 +4,6 @@ CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" source "$CURRENT_DIR/shared_functions.sh" -# TMUX messaging is weird. You only get a nice clean pane if you do it with -# `run-shell` command. -echo_message() { - local message=$1 - tmux run-shell "echo '$message'" -} - end_message() { echo_message "" echo_message "TMUX environment reloaded." @@ -33,13 +26,6 @@ clone_plugin() { clone "https://github.com/$plugin" } -plugin_already_cloned() { - local plugin=$1 - local plugin_path=$(shared_plugin_path "$plugin") - cd $plugin_path && - git remote -} - pull_changes() { local plugin=$1 local plugin_path=$(shared_plugin_path "$plugin") @@ -51,7 +37,7 @@ pull_changes() { # pull new changes or clone plugin install_plugin() { local plugin=$1 - if plugin_already_cloned "$plugin"; then + if plugin_already_installed "$plugin"; then # plugin is already installed echo_message "Already installed $plugin" else diff --git a/scripts/shared_functions.sh b/scripts/shared_functions.sh index 8beae6f..811cc5e 100644 --- a/scripts/shared_functions.sh +++ b/scripts/shared_functions.sh @@ -29,3 +29,21 @@ shared_plugin_path() { local plugin_name=$(shared_plugin_name "$plugin") 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. +echo_message() { + 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") + cd $plugin_path && + git remote >/dev/null 2>&1 +} diff --git a/scripts/update_plugin.sh b/scripts/update_plugin.sh new file mode 100755 index 0000000..6570596 --- /dev/null +++ b/scripts/update_plugin.sh @@ -0,0 +1,34 @@ +#!/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 )" + +source "$CURRENT_DIR/shared_functions.sh" + +display_plugin_update_list() { + local plugins="$(shared_get_tpm_plugins_list)" + for plugin in $plugins; do + # displaying only installed plugins + if plugin_already_cloned "$plugin"; then + echo_message "$plugin" + fi + done +} + +update_plugin_prompt() { + tmux command-prompt -p 'plugin update:' " \ + send-keys C-m; \ + run-shell '$CURRENT_DIR/update_plugin.sh %1'" +} + + +main() { + reload_tmux_environment + shared_set_tpm_path_constant + display_plugin_update_list + update_plugin_prompt +} +main diff --git a/scripts/update_plugin_prompt.sh b/scripts/update_plugin_prompt.sh new file mode 100755 index 0000000..acff43e --- /dev/null +++ b/scripts/update_plugin_prompt.sh @@ -0,0 +1,43 @@ +#!/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 )" + +source "$CURRENT_DIR/shared_functions.sh" + +display_plugin_update_list() { + local plugins="$(shared_get_tpm_plugins_list)" + echo_message "Installed plugins:" + echo_message "" + + for plugin in $plugins; do + # displaying only installed plugins + if plugin_already_installed "$plugin"; then + echo_message " $plugin" + fi + done + + echo_message "" + echo_message "Type (full) plugin name to update it." + echo_message "* - updates all." + echo_message "" + echo_message "ENTER - cancels" +} + +update_plugin_prompt() { + tmux command-prompt -p 'plugin update:' " \ + send-keys C-m; \ + run-shell '$CURRENT_DIR/update_plugin.sh %1'" +} + + +main() { + reload_tmux_environment + shared_set_tpm_path_constant + display_plugin_update_list + update_plugin_prompt +} +main diff --git a/tpm b/tpm index f03152c..49027e7 100755 --- a/tpm +++ b/tpm @@ -27,6 +27,7 @@ source_plugins() { # prefix + I - downloads TPM plugins and reloads TMUX environment. set_tpm_key_binding() { tmux bind-key I run-shell "$CURRENT_DIR/scripts/install_plugins.sh >/dev/null 2>&1" + tmux bind-key U run-shell "$CURRENT_DIR/scripts/update_plugin_prompt.sh" } supported_tmux_version_ok() {