Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding optional alias to plugin definitions for git clone operations #315

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions scripts/helpers/plugin_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,13 @@ tpm_plugins_list_helper() {
# 1. "git://github.com/user/plugin_name.git"
# 2. "user/plugin_name"
plugin_name_helper() {
local plugin="$1"
local plugin="${1%%;*}"
local alias=$(echo $1 | sed -E 's/.*alias[[:space:]]*[:=][[:space:]]*//')

[[ "$alias" == "$1" ]] && alias=""

# get only the part after the last slash, e.g. "plugin_name.git"
local plugin_basename="$(basename "$plugin")"
local plugin_basename=$([[ -n "$alias" ]] && echo "$alias" || basename "$plugin")
# remove ".git" extension (if it exists) to get only "plugin_name"
local plugin_name="${plugin_basename%.git}"
echo "$plugin_name"
Expand Down
29 changes: 17 additions & 12 deletions scripts/install_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ fi
clone() {
local plugin="$1"
local branch="$2"
if [ -n "$branch" ]; then
cd "$(tpm_path)" &&
GIT_TERMINAL_PROMPT=0 git clone -b "$branch" --single-branch --recursive "$plugin" >/dev/null 2>&1
else
cd "$(tpm_path)" &&
GIT_TERMINAL_PROMPT=0 git clone --single-branch --recursive "$plugin" >/dev/null 2>&1
fi
local alias="$3"
cd "$(tpm_path)" && {
local git_cmd=(git clone --single-branch --recursive)
[ -n "$branch" ] && git_cmd+=(-b "$branch")
git_cmd+=("$plugin" ${alias:+"$alias"})

GIT_TERMINAL_PROMPT=0 "${git_cmd[@]}" >/dev/null 2>&1
}
}

# tries cloning:
Expand All @@ -30,21 +31,25 @@ clone() {
clone_plugin() {
local plugin="$1"
local branch="$2"
clone "$plugin" "$branch" ||
clone "https://git::@github.com/$plugin" "$branch"
local alias="$3"
clone "$plugin" "$branch" "$alias" ||
clone "https://git::@github.com/$plugin" "$branch" "$alias"
}

# clone plugin and produce output
install_plugin() {
local plugin="$1"
local branch="$2"
local plugin="${1%%;*}"
local alias=$(echo $1$2 | sed -E 's/.*alias[[:space:]]*[:=][[:space:]]*//')
local branch="${2%%;*}"
local plugin_name="$(plugin_name_helper "$plugin")"

[[ "$alias" == "$1$2" ]] && alias=""

if plugin_already_installed "$plugin"; then
echo_ok "Already installed \"$plugin_name\""
else
echo_ok "Installing \"$plugin_name\""
clone_plugin "$plugin" "$branch" &&
clone_plugin "$plugin" "$branch" "$alias" &&
echo_ok " \"$plugin_name\" download success" ||
echo_err " \"$plugin_name\" download fail"
fi
Expand Down