feat: support for user/repo and ssh

This commit is contained in:
o0th 2025-09-10 10:37:54 +02:00
parent 913f29af86
commit 9e452112d9
3 changed files with 39 additions and 17 deletions

View file

@ -82,10 +82,21 @@ tpm_plugins_list_helper() {
# 2. "user/plugin_name"
plugin_name_helper() {
local plugin="$1"
# 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"
# 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"
}

View file

@ -14,15 +14,26 @@ fi
clone() {
local plugin="$1"
[[ -z "$2" ]] && local branch="" || local branch="--branch $2"
if [[ ! $plugin == *"https://"* ]]; 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 $branch --single-branch --recursive "https://git::@github.com/$plugin" $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
local basename_with_git="$(basename "$plugin")"
local basename="${basename_with_git%.git}"
cd "$(tpm_path)" &&
GIT_TERMINAL_PROMPT=0 git clone $branch --single-branch --recursive "$basename" $basename >/dev/null 2>&1
GIT_TERMINAL_PROMPT=0 git clone $clone_options --single-branch --recursive "$plugin" "$plugin_name" >/dev/null 2>&1
fi
}

View file

@ -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!" &