feat: add support for installing two plugins with same name
This commit is contained in:
parent
b699a7e01c
commit
8eb8d83261
2 changed files with 16 additions and 6 deletions
|
@ -80,8 +80,15 @@ tpm_plugins_list_helper() {
|
|||
# Allowed plugin name formats:
|
||||
# 1. "git://github.com/user/plugin_name.git"
|
||||
# 2. "user/plugin_name"
|
||||
# 3. "plugin_name::git://github.com/user/plugin_name.git"
|
||||
# 4. "plugin_name::user/plugin"
|
||||
plugin_name_helper() {
|
||||
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"
|
||||
local plugin_basename="$(basename "$plugin")"
|
||||
# remove ".git" extension (if it exists) to get only "plugin_name"
|
||||
|
|
|
@ -15,12 +15,13 @@ fi
|
|||
clone() {
|
||||
local plugin="$1"
|
||||
local branch="$2"
|
||||
local plugin_name="$3"
|
||||
if [ -n "$branch" ]; 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 -b "$branch" --single-branch --recursive "$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 --single-branch --recursive "$plugin" "$plugin_name" >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -28,10 +29,12 @@ clone() {
|
|||
# 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"
|
||||
# strip the eventual plugin name
|
||||
local plugin="${1#*::}"
|
||||
local branch="$2"
|
||||
clone "$plugin" "$branch" ||
|
||||
clone "https://git::@github.com/$plugin" "$branch"
|
||||
local plugin_name="$3"
|
||||
clone "$plugin" "$branch" "$plugin_name" ||
|
||||
clone "https://git::@github.com/$plugin" "$branch" "$plugin_name"
|
||||
}
|
||||
|
||||
# clone plugin and produce output
|
||||
|
@ -44,7 +47,7 @@ install_plugin() {
|
|||
echo_ok "Already installed \"$plugin_name\""
|
||||
else
|
||||
echo_ok "Installing \"$plugin_name\""
|
||||
clone_plugin "$plugin" "$branch" &&
|
||||
clone_plugin "$plugin" "$branch" "$plugin_name" &&
|
||||
echo_ok " \"$plugin_name\" download success" ||
|
||||
echo_err " \"$plugin_name\" download fail"
|
||||
fi
|
||||
|
|
Loading…
Reference in a new issue