]> arthur.barton.de Git - ax-zsh.git/commitdiff
axzshctl check-plugins: Use a subshell and cache core zshrc-stage plugins
authorAlexander Barton <alex@barton.de>
Sun, 22 Nov 2020 23:32:12 +0000 (00:32 +0100)
committerAlexander Barton <alex@barton.de>
Sun, 22 Nov 2020 23:32:12 +0000 (00:32 +0100)
This reduces execution time of "axzshctl check-plugins" on one of my
macOS machines from ~24 down to ~8 seconds. Wow!

bin/axzshctl

index 17cea907be0c8c801523630b1bef2c60508b275d..c8aaf7da3e03cb62ad31223a8c81da759e80d35e 100755 (executable)
@@ -323,6 +323,18 @@ function CheckPlugins {
        missing_plugins=()
        invalid_plugins=()
 
+       # Building cache file for all zshrc core files:
+       if ! T=$(mktemp); then
+               ax_error "Failed to create temporary file!"
+               return 1
+       fi
+       for p in $AXZSH/core/*/*.zshrc; do
+               [[ "$(basename "$p")" == "01_zprofile.zshrc" ]] && continue
+               printf "# BEGIN: %s\nax_plugin_init()\n{\n" "$p" >>"$T"
+               cat "$p" >>"$T"
+               printf "}\nax_plugin_init\n# END: %s\n\n" "$p" >>"$T"
+       done
+
        ax_msg - "Checking plugins ..."
        for dir ($AXZSH/plugins/[a-z0-9]*(N)); do
                plugin=${dir:t}
@@ -340,10 +352,13 @@ function CheckPlugins {
                new_plugin=""
                for script ($AXZSH/plugins/$plugin/$plugin.{zshrc,zprofile,ax-io}); do
                        [[ -r "$script" ]] || continue
-                       AXZSH_PLUGIN_CHECK=1 zsh -i -c "source $script"; r=$?
-                       if [[ $r -eq 0 ]]; then
-                               new_plugin=$plugin
-                       fi
+                       (
+                               AXZSH_PLUGIN_CHECK=1
+                               source "$T"
+                               ax_plugin_fnc() { source "$script" }
+                               ax_plugin_fnc
+                       ); r=$?
+                       [[ $r -eq 0 ]] && new_plugin=$plugin
                        break
                done
                if [[ -n "$new_plugin" ]]; then
@@ -359,6 +374,7 @@ function CheckPlugins {
                        ax_msg 2 "failed ($r)."
                fi
        done
+       rm -f "$T"
        echo
 
        result=0