axzshctl: Handle themes on "disable-plugin" & clean up repositories
authorAlexander Barton <alex@barton.de>
Sat, 15 Feb 2020 16:34:15 +0000 (17:34 +0100)
committerAlexander Barton <alex@barton.de>
Sat, 15 Feb 2020 16:34:15 +0000 (17:34 +0100)
handle plugins providing a theme, and try to remove cloned repositories
not only when disabling a plugin succeeded, but always.

bin/axzshctl

index 1c41425990e0fb4091d6a2a5bd43a1a97fb5cb9c..cd463e3ded886e9f5b4ab08bed5925d00b8e9e22 100755 (executable)
@@ -152,14 +152,29 @@ function EnablePlugin {
 function DisablePlugin {
        local plugin=$(NormalizedPluginName "$1")
        local dir="$AXZSH/active_plugins"
+       local r=-1
 
-       if [[ ! -h "$dir/$plugin" ]]; then
-               ax_msg 1 "Plugin \"$1\" not active?"
-               return 1
+       # Active theme?
+       if [[ $(readlink "$AXZSH/active_theme") = "$AXZSH/repos/$plugin/"* ]]; then
+               rm "$AXZSH/active_theme"; r=$?
+       fi
+
+       # Active plugin?
+       if [[ -h "$dir/$plugin" ]]; then
+               rm "$dir/$plugin"; r=$?
+       fi
+
+       if [[ $r -eq -1 ]]; then
+               ax_msg 1 "Plugin \"$1\" not active, nothing to do?"
+               r=1
+       fi
+
+       if [[ "$plugin" = *"#"* ]]; then
+               # Name matches a cloned repository, try to clean up!
+               echo "Cleaning up cloned repository ..."
+               rm -fr "$AXZSH/repos/$plugin"
        fi
 
-       rm -v "$dir/$plugin"; r=$?
-       [ $r -eq 0 ] && rm -fr "$AXZSH/repos/$plugin"
        return $r
 }