1
0
Fork 0
mirror of synced 2024-12-14 03:15:47 -05:00

feat: add support for installing two plugins with same name

This commit is contained in:
cubercsl 2022-01-23 17:09:27 +08:00
parent b699a7e01c
commit 8eb8d83261
No known key found for this signature in database
GPG key ID: 45C64B19E9161E41
2 changed files with 16 additions and 6 deletions

View file

@ -80,8 +80,15 @@ tpm_plugins_list_helper() {
# Allowed plugin name formats: # Allowed plugin name formats:
# 1. "git://github.com/user/plugin_name.git" # 1. "git://github.com/user/plugin_name.git"
# 2. "user/plugin_name" # 2. "user/plugin_name"
# 3. "plugin_name::git://github.com/user/plugin_name.git"
# 4. "plugin_name::user/plugin"
plugin_name_helper() { plugin_name_helper() {
local plugin="$1" local plugin="$1"
# if a plugin name is specified, use it
if [[ "$plugin" = *::* ]]; then
echo "${plugin%%::*}"
return
fi
# get only the part after the last slash, e.g. "plugin_name.git" # get only the part after the last slash, e.g. "plugin_name.git"
local plugin_basename="$(basename "$plugin")" local plugin_basename="$(basename "$plugin")"
# remove ".git" extension (if it exists) to get only "plugin_name" # remove ".git" extension (if it exists) to get only "plugin_name"

View file

@ -15,12 +15,13 @@ fi
clone() { clone() {
local plugin="$1" local plugin="$1"
local branch="$2" local branch="$2"
local plugin_name="$3"
if [ -n "$branch" ]; then if [ -n "$branch" ]; then
cd "$(tpm_path)" && 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 -b "$branch" --single-branch --recursive "$plugin" "$plugin_name" >/dev/null 2>&1
else else
cd "$(tpm_path)" && cd "$(tpm_path)" &&
GIT_TERMINAL_PROMPT=0 git clone --single-branch --recursive "$plugin" >/dev/null 2>&1 GIT_TERMINAL_PROMPT=0 git clone --single-branch --recursive "$plugin" "$plugin_name" >/dev/null 2>&1
fi fi
} }
@ -28,10 +29,12 @@ clone() {
# 1. plugin name directly - works if it's a valid git url # 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 # 2. expands the plugin name to point to a GitHub repo and tries cloning again
clone_plugin() { clone_plugin() {
local plugin="$1" # strip the eventual plugin name
local plugin="${1#*::}"
local branch="$2" local branch="$2"
clone "$plugin" "$branch" || local plugin_name="$3"
clone "https://git::@github.com/$plugin" "$branch" clone "$plugin" "$branch" "$plugin_name" ||
clone "https://git::@github.com/$plugin" "$branch" "$plugin_name"
} }
# clone plugin and produce output # clone plugin and produce output
@ -44,7 +47,7 @@ install_plugin() {
echo_ok "Already installed \"$plugin_name\"" echo_ok "Already installed \"$plugin_name\""
else else
echo_ok "Installing \"$plugin_name\"" echo_ok "Installing \"$plugin_name\""
clone_plugin "$plugin" "$branch" && clone_plugin "$plugin" "$branch" "$plugin_name" &&
echo_ok " \"$plugin_name\" download success" || echo_ok " \"$plugin_name\" download success" ||
echo_err " \"$plugin_name\" download fail" echo_err " \"$plugin_name\" download fail"
fi fi