]> arthur.barton.de Git - ax-zsh.git/commitdiff
Add support for remote OhMyZsh plugins
authorAlexander Barton <alex@barton.de>
Fri, 30 Apr 2021 11:03:19 +0000 (13:03 +0200)
committerAlexander Barton <alex@barton.de>
Fri, 30 Apr 2021 11:03:19 +0000 (13:03 +0200)
OhMyZsh plugins are referenced by an "@ohmyzsh/<name>" identifier, and
the OhMyZsh source tree is cloned with Git as needed.

bin/axzshctl
core/50_axzsh/functions/_axzsh

index 7d85c4d01dd93c5eff3b3b7da408cfdc6f82a1ba..f41550e14c11780633ab7bc1e608daa630577a1f 100755 (executable)
@@ -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
index 7e0209981fa93e1cf26ef4bf2a526ad26c812420..960a76b9d59333c88def4467608316f18a5b79a1 100644 (file)
@@ -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 "$@" -- \