From 73a419c5997ec6e8257db0a114941d1d328bfd30 Mon Sep 17 00:00:00 2001 From: Ashish Shah Date: Thu, 23 Nov 2017 15:06:54 -0600 Subject: [PATCH] Add ability to use branches for plugins --- scripts/helpers/plugin_functions.sh | 2 +- scripts/install_plugins.sh | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index d2778d5..4e2267f 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -56,7 +56,7 @@ tpm_plugins_list_helper() { # read set -g @plugin "tmux-plugins/tmux-example-plugin" entries _tmux_conf_contents "full" | - awk '/^[ \t]*set(-option)? +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); print $4 }' + awk '/^[ \t]*set(-option)? +-g +@plugin/ { gsub(/'\''/,""); gsub(/'\"'/,""); gsub(/#/, " "); print $4","$5 }' } # Allowed plugin name formats: diff --git a/scripts/install_plugins.sh b/scripts/install_plugins.sh index 7958ab5..ee07252 100755 --- a/scripts/install_plugins.sh +++ b/scripts/install_plugins.sh @@ -14,8 +14,12 @@ fi clone() { local plugin="$1" - cd "$(tpm_path)" && - GIT_TERMINAL_PROMPT=0 git clone --recursive "$plugin" >/dev/null 2>&1 + local branch="$2" + if [ ! -z "$branch" ]; then + cd "$(tpm_path)" && GIT_TERMINAL_PROMPT=0 git clone --recursive -b "$branch" "$plugin" >/dev/null 2>&1 + else + cd "$(tpm_path)" && GIT_TERMINAL_PROMPT=0 git clone --recursive "$plugin" >/dev/null 2>&1 + fi } # tries cloning: @@ -23,20 +27,22 @@ clone() { # 2. expands the plugin name to point to a github repo and tries cloning again clone_plugin() { local plugin="$1" - clone "$plugin" || - clone "https://git::@github.com/$plugin" + local branch="$2" + clone "$plugin" "$branch" || + clone "https://git::@github.com/$plugin" "$branch" } # clone plugin and produce output install_plugin() { local plugin="$1" + local branch="$2" local plugin_name="$(plugin_name_helper "$plugin")" if plugin_already_installed "$plugin"; then echo_ok "Already installed \"$plugin_name\"" else echo_ok "Installing \"$plugin_name\"" - clone_plugin "$plugin" && + clone_plugin "$plugin" "$branch" && echo_ok " \"$plugin_name\" download success" || echo_err " \"$plugin_name\" download fail" fi @@ -44,8 +50,10 @@ install_plugin() { install_plugins() { local plugins="$(tpm_plugins_list_helper)" - for plugin in $plugins; do - install_plugin "$plugin" + for plugin_line in $plugins; do + local plugin=$(echo $plugin_line | awk -F',' '{print $1}') + local branch=$(echo $plugin_line | awk -F',' '{print $2}') + install_plugin "$plugin" "$branch" done }