From 15f0cf1b5813fb6b9159d71edcfcba952d57eecb Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Sun, 11 Feb 2018 11:12:23 +0100 Subject: [PATCH] Enhance support for remote plugins with embedded themes 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 | 3 +++ bin/axzshctl | 23 +++++++++++++++++++++-- core/50_axzsh/functions/_axzsh | 8 ++++++-- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/ax.zsh b/ax.zsh index 0071767..6915c46 100644 --- 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 diff --git a/bin/axzshctl b/bin/axzshctl index 335c993..a75ebb3 100755 --- a/bin/axzshctl +++ b/bin/axzshctl @@ -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 $? diff --git a/core/50_axzsh/functions/_axzsh b/core/50_axzsh/functions/_axzsh index e3ae175..2f6ab78 100644 --- a/core/50_axzsh/functions/_axzsh +++ b/core/50_axzsh/functions/_axzsh @@ -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 ;; -- 2.39.2