Skip to content

Commit 7edf204

Browse files
committed
manually implementing tmux-plugins/pull/274 with some additional bash syntax fixes for mac
1 parent 99469c4 commit 7edf204

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

scripts/helpers/plugin_functions.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ tpm_plugins_list_helper() {
8282
# 2. "user/plugin_name"
8383
plugin_name_helper() {
8484
local plugin="$1"
85-
# get only the part after the last slash, e.g. "plugin_name.git"
86-
local plugin_basename="$(basename "$plugin")"
87-
# remove ".git" extension (if it exists) to get only "plugin_name"
88-
local plugin_name="${plugin_basename%.git}"
85+
# get only the last two path segments as author/repo
86+
IFS='/' read -ra plugin <<< "$plugin"
87+
plugin="${plugin[*]: -2:1}/${plugin[*]: -1}"
88+
89+
# remove ".git" extension (if it exists) to get only "plugin_name"
90+
local plugin_name="${plugin%.git}"
8991
echo "$plugin_name"
9092
}
9193

@@ -97,7 +99,8 @@ plugin_path_helper() {
9799

98100
plugin_already_installed() {
99101
local plugin="$1"
100-
local plugin_path="$(plugin_path_helper "$plugin")"
102+
IFS='#' read -ra plugin <<< "$plugin"
103+
local plugin_path="$(plugin_path_helper "${plugin[0]}")"
101104
[ -d "$plugin_path" ] &&
102105
cd "$plugin_path" &&
103106
git remote >/dev/null 2>&1

scripts/install_plugins.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@ fi
1414

1515
clone() {
1616
local plugin="$1"
17-
local branch="$2"
18-
if [ -n "$branch" ]; then
17+
[[ -z "$2" ]] && local branch="" || local branch="--branch $2"
18+
if [[ ! $plugin == *"https://"* ]]; then
1919
cd "$(tpm_path)" &&
20-
GIT_TERMINAL_PROMPT=0 git clone -b "$branch" --single-branch --recursive "$plugin" >/dev/null 2>&1
20+
GIT_TERMINAL_PROMPT=0 git clone $branch --single-branch --recursive "https://git::@github.com/$plugin" $plugin >/dev/null 2>&1
2121
else
22+
local basename_with_git="$(basename "$plugin")"
23+
local basename="${basename_with_git%.git}"
2224
cd "$(tpm_path)" &&
23-
GIT_TERMINAL_PROMPT=0 git clone --single-branch --recursive "$plugin" >/dev/null 2>&1
25+
GIT_TERMINAL_PROMPT=0 git clone $branch --single-branch --recursive "$basename" $basename >/dev/null 2>&1
2426
fi
2527
}
2628

27-
# tries cloning:
28-
# 1. plugin name directly - works if it's a valid git url
29-
# 2. expands the plugin name to point to a GitHub repo and tries cloning again
3029
clone_plugin() {
3130
local plugin="$1"
3231
local branch="$2"

0 commit comments

Comments
 (0)