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: diff --git a/scripts/helpers/plugin_functions.sh b/scripts/helpers/plugin_functions.sh index f33d215..84417c9 100644 --- a/scripts/helpers/plugin_functions.sh +++ b/scripts/helpers/plugin_functions.sh @@ -82,10 +82,22 @@ 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")" - # remove ".git" extension (if it exists) to get only "plugin_name" - local plugin_name="${plugin_basename%.git}" + # Extract user/repo from different URL formats + if [[ "$plugin" == "https://"* ]] || [[ "$plugin" == "git@"* ]]; then + # Handle full URLs + plugin=$(echo "$plugin" | sed -E 's/.*[\/:]([^\/]+\/[^\/]+)\.git?$/\1/') + else + # Handle user/repo format + IFS='/' read -ra plugin_parts <<< "$plugin" + if [[ ${#plugin_parts[@]} -eq 2 ]]; then + plugin="${plugin_parts[0]}/${plugin_parts[1]}" + else + # get only the last two parts for longer paths + plugin="${plugin_parts[-2]}/${plugin_parts[-1]}" + fi + fi + # remove ".git" extension (if it exists) to get only "user/repo" + local plugin_name="${plugin%.git}" echo "$plugin_name" } @@ -97,7 +109,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 diff --git a/scripts/install_plugins.sh b/scripts/install_plugins.sh index e2450ac..cdc78f8 100755 --- a/scripts/install_plugins.sh +++ b/scripts/install_plugins.sh @@ -14,19 +14,29 @@ fi clone() { local plugin="$1" - local branch="$2" - if [ -n "$branch" ]; then + local ref="$2" + local clone_options="" + + # Handle both branches and tags + if [[ -n "$ref" ]]; then + clone_options="--branch $ref" + fi + + local plugin_name="$(plugin_name_helper "$plugin")" + local plugin_dir="$(tpm_path)${plugin_name}/" + + # Create the user directory if it doesn't exist + mkdir -p "$(dirname "$plugin_dir")" + + if [[ ! $plugin == *"https://"* ]] && [[ ! $plugin == *"git@"* ]]; 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 $clone_options --single-branch --recursive "https://git::@github.com/$plugin" "$plugin_name" >/dev/null 2>&1 else cd "$(tpm_path)" && - GIT_TERMINAL_PROMPT=0 git clone --single-branch --recursive "$plugin" >/dev/null 2>&1 + GIT_TERMINAL_PROMPT=0 git clone $clone_options --single-branch --recursive "$plugin" "$plugin_name" >/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" diff --git a/scripts/update_plugin.sh b/scripts/update_plugin.sh index e533664..833ac81 100755 --- a/scripts/update_plugin.sh +++ b/scripts/update_plugin.sh @@ -42,10 +42,10 @@ update_all() { echo_ok "" local plugins="$(tpm_plugins_list_helper)" for plugin in $plugins; do - IFS='#' read -ra plugin <<< "$plugin" - local plugin_name="$(plugin_name_helper "${plugin[0]}")" - # updating only installed plugins - if plugin_already_installed "$plugin_name"; then + IFS='#' read -ra plugin_parts <<< "$plugin" + local plugin_name="$(plugin_name_helper "${plugin_parts[0]}")" + # updating only installed plugins - check with full plugin spec to handle branch/tag + if plugin_already_installed "$plugin"; then update "$plugin_name" & fi done @@ -55,9 +55,9 @@ update_all() { update_plugins() { local plugins="$*" for plugin in $plugins; do - IFS='#' read -ra plugin <<< "$plugin" - local plugin_name="$(plugin_name_helper "${plugin[0]}")" - if plugin_already_installed "$plugin_name"; then + IFS='#' read -ra plugin_parts <<< "$plugin" + local plugin_name="$(plugin_name_helper "${plugin_parts[0]}")" + if plugin_already_installed "$plugin"; then update "$plugin_name" & else echo_err "$plugin_name not installed!" &