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

Fix naming conflicts and tags #274

Open
wants to merge 4 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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Requirements: `tmux` version 1.9 (or higher), `git`, `bash`.
Clone TPM:

```bash
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tmux-plugins/tpm
```

Put this at the bottom of `~/.tmux.conf` (`$XDG_CONFIG_HOME/tmux/tmux.conf`
Expand All @@ -28,12 +28,12 @@ set -g @plugin 'tmux-plugins/tmux-sensible'

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'github_username/plugin_name#branch'
# set -g @plugin 'github_username/plugin_name#branch_or_tag'
# set -g @plugin 'git@github.com:user/plugin'
# set -g @plugin 'git@bitbucket.com:user/plugin'

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'
run '~/.tmux/plugins/tmux-plugins/tpm/tpm'
```

Reload TMUX environment so TPM is sourced:
Expand Down
10 changes: 6 additions & 4 deletions scripts/helpers/plugin_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ 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")"
# get only the last part

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This comment provides less context than the original, I think remove it, since the comment for the function is doing the same job.

IFS='/' read -ra plugin <<< "$plugin"
plugin="${plugin[-2]}/${plugin[-1]}"
# remove ".git" extension (if it exists) to get only "plugin_name"
local plugin_name="${plugin_basename%.git}"
local plugin_name="${plugin%.git}"
echo "$plugin_name"
}

Expand All @@ -97,7 +98,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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be misreading this but does this not break the case where the plugin URL is intended to use SSH? i.e. git@github.com:user/plugin, and git@bitbucket.com:user/plugin, effectively removing SSH support for non-GitHub sources?

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