Skip to content

Commit

Permalink
manually implementing tmux-plugins/pull/274 with some additional bash…
Browse files Browse the repository at this point in the history
… syntax fixes for mac
  • Loading branch information
dgiunta committed Jun 11, 2024
1 parent 99469c4 commit 7edf204
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 8 additions & 5 deletions scripts/helpers/plugin_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ 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}"
# get only the last two path segments as author/repo
IFS='/' read -ra plugin <<< "$plugin"
plugin="${plugin[*]: -2:1}/${plugin[*]: -1}"

# remove ".git" extension (if it exists) to get only "plugin_name"
local plugin_name="${plugin%.git}"
echo "$plugin_name"
}

Expand All @@ -97,7 +99,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
Expand Down
13 changes: 6 additions & 7 deletions scripts/install_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ fi

clone() {
local plugin="$1"
local branch="$2"
if [ -n "$branch" ]; then
[[ -z "$2" ]] && local branch="" || local branch="--branch $2"
if [[ ! $plugin == *"https://"* ]]; 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 $branch --single-branch --recursive "https://git::@github.com/$plugin" $plugin >/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 --single-branch --recursive "$plugin" >/dev/null 2>&1
GIT_TERMINAL_PROMPT=0 git clone $branch --single-branch --recursive "$basename" $basename >/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"
Expand Down

0 comments on commit 7edf204

Please sign in to comment.