From 0671c24a0a0c9b9ab7bc1383ac1cf413c1b78813 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Fri, 30 Apr 2021 13:03:19 +0200 Subject: [PATCH] Add support for remote OhMyZsh plugins OhMyZsh plugins are referenced by an "@ohmyzsh/" identifier, and the OhMyZsh source tree is cloned with Git as needed. --- bin/axzshctl | 20 +++++++++++++++++--- core/50_axzsh/functions/_axzsh | 5 +++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bin/axzshctl b/bin/axzshctl index 7d85c4d..f41550e 100755 --- a/bin/axzshctl +++ b/bin/axzshctl @@ -90,7 +90,7 @@ function UpdatePluginCache { } function NormalizedPluginName { - if [[ "$1" =~ "^[[:alnum:]-]+/[[:alnum:]_.-]+$" ]]; then + if [[ "$1" =~ "^@?[[:alnum:]-]+/[[:alnum:]_.-]+$" ]]; then echo "${1:gs/\//#}" elif [[ "$1" =~ "/" ]]; then echo "${1:t}" @@ -121,13 +121,27 @@ function DisableAXZSH { function EnablePlugin { local plugin=$(NormalizedPluginName "$1") local dir="$AXZSH/active_plugins" + local name="$plugin" if [[ -h "$dir/$plugin" ]]; then ax_msg 1 "Plugin \"$1\" already active!" return 1 fi - if [[ "$1" =~ "^[[:alnum:]-]+/[[:alnum:]_.-]+$" ]]; then + if [[ "$1" =~ "^@[[:alnum:]-]+/[[:alnum:]_.+]+$" ]]; then + # GitHub plugin repository (like OhMyZsh) + local repo="${1##@}" + repo="${repo%/*}" + mkdir -p "$AXZSH/repos/@$repo" + if [[ ! -d "$AXZSH/repos/@$repo/plugins" ]]; then + ax_msg - "Cloning \"$repo\" from GitHub ..." + git clone --depth=1 "https://github.com/$repo/$repo.git" \ + "$AXZSH/repos/@$repo" \ + || ax_error "Failed to clone \"$repo\" repository!" + fi + plugin="@$repo/plugins/${1#*/}" + echo "Trying to enable \"$1\" ..." + elif [[ "$1" =~ "^[[:alnum:]-]+/[[:alnum:]_.-]+$" ]]; then # GitHub plugin mkdir -p "$AXZSH/repos" if [[ ! -e "$AXZSH/repos/$plugin" ]]; then @@ -165,7 +179,7 @@ function EnablePlugin { mkdir -p "$dir" if ! ( cd "$dir" || exit 9 - ln -s "$dname" "$PWD" + ln -s "$dname" "$PWD/$name" ); then ax_error "Failed to create link!" return 1 diff --git a/core/50_axzsh/functions/_axzsh b/core/50_axzsh/functions/_axzsh index 7e02099..960a76b 100644 --- a/core/50_axzsh/functions/_axzsh +++ b/core/50_axzsh/functions/_axzsh @@ -25,6 +25,11 @@ _axzshctl() { "$AXZSH"/plugins/*(/:t) \ "$AXZSH"/custom_plugins/*(N/:t) \ "$AXZSH"/repos/*(/:t:s/#/\\/) + for r in "$AXZSH"/repos/@*(N/); do + b=(echo $r(:t)) + compadd "$@" -- \ + $(echo $r/plugins/*(N:t) | sed -E "s/(^| )/ $b\//g") + done ;; "disable-plugin") compadd "$@" -- \ -- 2.39.2