]> arthur.barton.de Git - ax-zsh.git/commitdiff
Enhance support for remote plugins with embedded themes
authorAlexander Barton <alex@barton.de>
Sun, 11 Feb 2018 10:12:23 +0000 (11:12 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 11 Feb 2018 10:12:23 +0000 (11:12 +0100)
Enable a theme in a remote plugins automatically when cloning and
enabling the plugin itself, and add support to enable such themes
using the regular "axzshctl set-theme" command.

ax.zsh
bin/axzshctl
core/50_axzsh/functions/_axzsh

diff --git a/ax.zsh b/ax.zsh
index 0071767967b2a04e6a8f363b2c1d437cb48e7468..6915c467e8803c3b3b6d25d95d44962260234870 100644 (file)
--- a/ax.zsh
+++ b/ax.zsh
@@ -49,6 +49,9 @@ function axzsh_load_plugin {
                        # Prezto module
                        type="init.zsh"
                        fname="$dname/init.zsh"
+               elif [[ -r "$dname/$plugin.zsh-theme" ]]; then
+                       # ZSH "theme plugin", ignore here!
+                       :
                else
                        echo "AX-ZSH plugin type of \"$plugin\" unknown, skipped!" >&2
                        return 0
index 335c9938a302e8fe709dde0115187018774e243c..a75ebb3db750e0d483c1de6047bd4fd07d6ba3e4 100755 (executable)
@@ -110,6 +110,10 @@ function EnablePlugin {
                        ax_msg - "Cloning plugin from GitHub ..."
                        git clone "https://github.com/$1.git" \
                         "$AXZSH/repos/$plugin"
+                       # Try to enable a theme in this "foreign" plugin, but
+                       # ignore errors: we don't know if this plugin provides
+                       # a theme at all ...
+                       SetTheme "${plugin#*#}" 2>/dev/null
                fi
        fi
 
@@ -206,8 +210,23 @@ function SetTheme {
        elif [ -r "$AXZSH/themes/$1.axzshtheme" ]; then
                theme="$AXZSH/themes/$1.axzshtheme"
        else
-               echo "Theme \"$1\" not found!"
-               return 1
+               # Look for theme inside of installed plugins:
+               for dname (
+                       "$AXZSH/custom_plugins/"*(N)
+                       "$AXZSH/repos/"*(N)
+               ); do
+                       if [[ -r "$dname/$1.axzshtheme" ]]; then
+                               theme="$dname/$1.axzshtheme"
+                               break
+                       elif [[ -r "$dname/$1.zsh-theme" ]]; then
+                               theme="$dname/$1.zsh-theme"
+                               break
+                       fi
+               done
+               if [[ -z "$theme" ]]; then
+                       echo "Theme \"$1\" not found!"
+                       return 1
+               fi
        fi
        ln -sv "$theme" "$link_name" || return 1
        return $?
index e3ae1755dd2702ade47c96a63b1e7745296a195c..2f6ab781f6c4b375c8c1138958e7cd3f8833b58b 100644 (file)
@@ -21,10 +21,14 @@ _axzshctl() {
          'args')
                case "$words[2]" in
                  "enable-plugin"|"disable-plugin")
-                       compadd "$@" -- $(ls -1 "$AXZSH"/plugins)
+                       compadd "$@" -- \
+                               $(ls -1 "$AXZSH"/plugins) \
+                               $(ls -1 "$AXZSH"/custom_plugins)
                        ;;
                  "set-theme")
-                       compadd "$@" -- "-" $(ls -1 "$AXZSH"/themes | cut -d'.' -f1)
+                       compadd "$@" -- "-" \
+                               $(ls -1 "$AXZSH"/themes | cut -d'.' -f1) \
+                               $(find "$AXZSH/custom_plugins" "$AXZSH/repos" -maxdepth 2 -iname '*.zsh-theme' -exec basename {} \; | cut -d'.' -f1)
                        ;;
                esac
                ;;