From 8d00915e83db5f28ccd0760f97d3379ce592e16b Mon Sep 17 00:00:00 2001 From: o0th Date: Wed, 7 Feb 2024 15:40:12 +0100 Subject: [PATCH 1/4] feat: install plugins as user/plugin --- scripts/helpers/plugin_functions.sh | 7 ++++--- scripts/install_plugins.sh | 24 +++++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index f33d215..e4122b3 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -82,10 +82,11 @@ tpm_plugins_list_helper() { # 2. "user/plugin_name" plugin_name_helper() { local plugin="$1" - # get only the part after the last slash, e.g. "plugin_name.git" - local plugin_basename="$(basename "$plugin")" + # get only the last part + IFS='/' read -ra plugin <<< "$plugin" + plugin="${plugin[-2]}/${plugin[-1]}" # remove ".git" extension (if it exists) to get only "plugin_name" - local plugin_name="${plugin_basename%.git}" + local plugin_name="${plugin%.git}" echo "$plugin_name" } diff --git a/scripts/install_plugins.sh b/scripts/install_plugins.sh index e2450ac..c0df4c4 100755 --- a/scripts/install_plugins.sh +++ b/scripts/install_plugins.sh @@ -14,19 +14,18 @@ fi clone() { local plugin="$1" - local branch="$2" - if [ -n "$branch" ]; then + [[ -z "$2" ]] && local branch="" || local branch="--branch $2" + if [[ ! $plugin == *"https://"* ]]; then cd "$(tpm_path)" && - GIT_TERMINAL_PROMPT=0 git clone -b "$branch" --single-branch --recursive "$plugin" >/dev/null 2>&1 + GIT_TERMINAL_PROMPT=0 git clone $branch --single-branch --recursive "https://git::@github.com/$plugin" $plugin >/dev/null 2>&1 else + local basename_with_git="$(basename "$plugin")" + local basename="${basename_with_git%.git}" cd "$(tpm_path)" && - GIT_TERMINAL_PROMPT=0 git clone --single-branch --recursive "$plugin" >/dev/null 2>&1 + GIT_TERMINAL_PROMPT=0 git clone $branch --single-branch --recursive "$basename" $basename >/dev/null 2>&1 fi } -# tries cloning: -# 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 branch="$2" @@ -53,8 +52,15 @@ install_plugin() { install_plugins() { local plugins="$(tpm_plugins_list_helper)" for plugin in $plugins; do - IFS='#' read -ra plugin <<< "$plugin" - install_plugin "${plugin[0]}" "${plugin[1]}" + if [[ "$plugin" == *#* ]]; then + IFS='#' read -ra plugin <<< "$plugin" + install_plugin "${plugin[0]}" "${plugin[1]}" + elif [[ "$plugin" == *@* ]]; then + IFS='@' read -ra plugin <<< "$plugin" + install_plugin "${plugin[0]}" "${plugin[1]}" + else + install_plugin ${plugin} + fi done } From 05ad8de77bd7fd0bf87d783a1087c1123b4f27c7 Mon Sep 17 00:00:00 2001 From: o0th Date: Wed, 7 Feb 2024 15:44:46 +0100 Subject: [PATCH 2/4] fix: revert do not use @ in plugin name --- scripts/install_plugins.sh | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/scripts/install_plugins.sh b/scripts/install_plugins.sh index c0df4c4..e054d0d 100755 --- a/scripts/install_plugins.sh +++ b/scripts/install_plugins.sh @@ -52,15 +52,8 @@ install_plugin() { install_plugins() { local plugins="$(tpm_plugins_list_helper)" for plugin in $plugins; do - if [[ "$plugin" == *#* ]]; then - IFS='#' read -ra plugin <<< "$plugin" - install_plugin "${plugin[0]}" "${plugin[1]}" - elif [[ "$plugin" == *@* ]]; then - IFS='@' read -ra plugin <<< "$plugin" - install_plugin "${plugin[0]}" "${plugin[1]}" - else - install_plugin ${plugin} - fi + IFS='#' read -ra plugin <<< "$plugin" + install_plugin "${plugin[0]}" "${plugin[1]}" done } From 4a798d85e1afb4b0aa3c8a40064538d589fced3b Mon Sep 17 00:00:00 2001 From: o0th Date: Wed, 7 Feb 2024 16:05:58 +0100 Subject: [PATCH 3/4] fix: onupdate show plugins with #branch/#tag --- scripts/helpers/plugin_functions.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index e4122b3..8d8932e 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -98,7 +98,8 @@ plugin_path_helper() { plugin_already_installed() { local plugin="$1" - local plugin_path="$(plugin_path_helper "$plugin")" + IFS='#' read -ra plugin <<< "$plugin" + local plugin_path="$(plugin_path_helper "${plugin[0]}")" [ -d "$plugin_path" ] && cd "$plugin_path" && git remote >/dev/null 2>&1 From 913f29af86a00aa738614d20413f7737429d3e38 Mon Sep 17 00:00:00 2001 From: o0th Date: Wed, 7 Feb 2024 16:12:21 +0100 Subject: [PATCH 4/4] fix: update readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2371863..f573cd5 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Requirements: `tmux` version 1.9 (or higher), `git`, `bash`. Clone TPM: ```bash -git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm +git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tmux-plugins/tpm ``` Put this at the bottom of `~/.tmux.conf` (`$XDG_CONFIG_HOME/tmux/tmux.conf` @@ -28,12 +28,12 @@ set -g @plugin 'tmux-plugins/tmux-sensible' # Other examples: # set -g @plugin 'github_username/plugin_name' -# set -g @plugin 'github_username/plugin_name#branch' +# set -g @plugin 'github_username/plugin_name#branch_or_tag' # set -g @plugin 'git@github.com:user/plugin' # set -g @plugin 'git@bitbucket.com:user/plugin' # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) -run '~/.tmux/plugins/tpm/tpm' +run '~/.tmux/plugins/tmux-plugins/tpm/tpm' ``` Reload TMUX environment so TPM is sourced: