]> arthur.barton.de Git - ax-zsh.git/blobdiff - bin/axzshctl
Introduce $AXZSH/custom_plugins directory
[ax-zsh.git] / bin / axzshctl
index ed3caf2baa186df73dae4df07830951fb8a189bc..82fb065bd858e69fa01fae5b9709aa30de870270 100755 (executable)
@@ -4,40 +4,55 @@
 # Copyright (c) 2015 Alexander Barton <alex@barton.de>
 #
 
+# Include "ax-common.sh", if available:
+for dir ("$HOME/lib" "$HOME/.ax" /usr/local /opt/ax /usr); do
+       [[ -z "$ax_common_sourced" ]] || break
+       ax_common="${dir}/lib/ax/ax-common.sh"
+       [[ -r "$ax_common" ]] && source "$ax_common"
+done
+if [[ -z "$ax_common_sourced" ]]; then
+       function ax_msg {
+               case "$1" in
+                 "1"|"2") echo -n "! "; ;;
+                 *) echo -n "* "; ;;
+               esac
+               shift
+               echo "$@"
+       }
+fi
+unset dir ax_common ax_common_sourced
+
 function Usage {
        echo "$NAME <command> [...]"
        echo
-       echo "  enable-plugin <p> [<p> [...]]"
+       echo "  enable-plugin <name|directory> [<name|directory> [...]]"
        echo "    Enable plugin(s)."
        echo
-       echo "  disable-plugin <p> [<p> [...]]"
+       echo "  disable-plugin <name> [<name> [...]]"
        echo "    Disable plugin(s)."
        echo
        echo "  reset-plugins"
-       echo "    Reset active plugins to the default list."
+       echo "    Reset active plugins to the default set."
+       echo
+       echo "  enable-default-plugins"
+       echo "    Enable all default plugins."
        echo
        exit 2
 }
 
-function Verbose {
-       echo "* $@"
-}
-
-function Warning {
-       echo "! $@"
-}
-
 function EnablePlugin {
        local dir="$AXZSH/active_plugins"
 
        if [[ -h "$dir/$1" ]]; then
-               Warning "Plugin \"$1\" already active!"
+               ax_msg 1 "Plugin \"$1\" already active!"
                return 1
        fi
 
        for dname (
+               "$plugin:A"
                "$AXZSH_PLUGIN_D/$plugin"
                "$ZSH_CUSTOM/$plugin"
+               "$AXZSH/custom_plugins/$plugin"
                "$AXZSH/plugins/$plugin"
                "$AXZSH/default_plugins/$plugin"
                "$AXZSH/core/$plugin"
@@ -51,7 +66,7 @@ function EnablePlugin {
                return $?
        done
 
-       Warning "Plugin \"$1\" not found!"
+       ax_msg 2 "Plugin \"$1\" not found!"
        return 1
 }
 
@@ -59,7 +74,7 @@ function DisablePlugin {
        local dir="$AXZSH/active_plugins"
 
        if [[ ! -h "$dir/$1" ]]; then
-               Warning "Plugin \"$1\" not active?"
+               ax_msg 1 "Plugin \"$1\" not active?"
                return 1
        fi
 
@@ -71,15 +86,20 @@ function ResetPlugins {
        local dir="$AXZSH/active_plugins"
 
        if [[ -e "$dir" ]]; then
-               Verbose "Removing all symbolic links in $dir ..."
+               ax_msg - "Removing all symbolic links in $dir ..."
                find "$dir" -type l -print -delete
        fi
+       return $?
+}
+
+function EnableDefaultPlugins {
+       local dir="$AXZSH/active_plugins"
 
-       Verbose "Activating (linking) default plugins ..."
+       ax_msg - "Activating (linking) default plugins ..."
        mkdir -p "$dir"
        (
                cd "$dir" || exit 9
-               ln -sv "$AXZSH/default_plugins/"* "$PWD"
+               ln -sfv "$AXZSH/default_plugins/"* "$PWD"
        )
        return $?
 }
@@ -89,7 +109,7 @@ NAME="$(basename "$0")"
 [[ $# -gt 0 ]] || Usage
 
 if [[ -z "$AXZSH" || ! -d "$AXZSH" ]]; then
-       echo "$NAME: Oops, \"AXZSH\" is not set or invalid!"
+       ax_msg 2 "Oops, \"AXZSH\" is not set or invalid!"
        exit 3
 fi
 
@@ -112,6 +132,11 @@ case "$cmd" in
        "reset-plugins")
                [[ $# -eq 0 ]] || Usage
                ResetPlugins
+               EnableDefaultPlugins
+               ;;
+       "enable-default-plugins")
+               [[ $# -eq 0 ]] || Usage
+               EnableDefaultPlugins
                ;;
        *)
                Usage