Skip to content
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 '[email protected]:user/plugin'
# set -g @plugin '[email protected]: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
23 changes: 18 additions & 5 deletions scripts/helpers/plugin_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,22 @@ 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}"
# Extract user/repo from different URL formats
if [[ "$plugin" == "https://"* ]] || [[ "$plugin" == "git@"* ]]; then
# Handle full URLs
plugin=$(echo "$plugin" | sed -E 's/.*[\/:]([^\/]+\/[^\/]+)\.git?$/\1/')
else
# Handle user/repo format
IFS='/' read -ra plugin_parts <<< "$plugin"
if [[ ${#plugin_parts[@]} -eq 2 ]]; then
plugin="${plugin_parts[0]}/${plugin_parts[1]}"
else
# get only the last two parts for longer paths
plugin="${plugin_parts[-2]}/${plugin_parts[-1]}"
fi
fi
# remove ".git" extension (if it exists) to get only "user/repo"
local plugin_name="${plugin%.git}"
echo "$plugin_name"
}

Expand All @@ -97,7 +109,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
24 changes: 17 additions & 7 deletions scripts/install_plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,29 @@ fi

clone() {
local plugin="$1"
local branch="$2"
if [ -n "$branch" ]; then
local ref="$2"
local clone_options=""

# Handle both branches and tags
if [[ -n "$ref" ]]; then
clone_options="--branch $ref"
fi

local plugin_name="$(plugin_name_helper "$plugin")"
local plugin_dir="$(tpm_path)${plugin_name}/"

# Create the user directory if it doesn't exist
mkdir -p "$(dirname "$plugin_dir")"

if [[ ! $plugin == *"https://"* ]] && [[ ! $plugin == *"git@"* ]]; 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 $clone_options --single-branch --recursive "https://git::@github.com/$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 $clone_options --single-branch --recursive "$plugin" "$plugin_name" >/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
14 changes: 7 additions & 7 deletions scripts/update_plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ update_all() {
echo_ok ""
local plugins="$(tpm_plugins_list_helper)"
for plugin in $plugins; do
IFS='#' read -ra plugin <<< "$plugin"
local plugin_name="$(plugin_name_helper "${plugin[0]}")"
# updating only installed plugins
if plugin_already_installed "$plugin_name"; then
IFS='#' read -ra plugin_parts <<< "$plugin"
local plugin_name="$(plugin_name_helper "${plugin_parts[0]}")"
# updating only installed plugins - check with full plugin spec to handle branch/tag
if plugin_already_installed "$plugin"; then
update "$plugin_name" &
fi
done
Expand All @@ -55,9 +55,9 @@ update_all() {
update_plugins() {
local plugins="$*"
for plugin in $plugins; do
IFS='#' read -ra plugin <<< "$plugin"
local plugin_name="$(plugin_name_helper "${plugin[0]}")"
if plugin_already_installed "$plugin_name"; then
IFS='#' read -ra plugin_parts <<< "$plugin"
local plugin_name="$(plugin_name_helper "${plugin_parts[0]}")"
if plugin_already_installed "$plugin"; then
update "$plugin_name" &
else
echo_err "$plugin_name not installed!" &
Expand Down