+function SetTheme {
+ local link_name="$AXZSH/active_theme"
+
+ # --- Powerlevel10k ---
+ # Remove "instant prompt" configuration, if any ...
+ rm -f "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
+
+ if [[ "$1" = "-" ]]; then
+ rm -f "$link_name" || return 1
+ ax_msg 0 "Theme settings have been reset."
+ return 0
+ fi
+
+ if [[ -r "$1" ]]; then
+ theme="$1"
+ elif [[ -r "$AXZSH/custom_themes/$1.axzshtheme" ]]; then
+ theme="$AXZSH/custom_themes/$1.axzshtheme"
+ elif [[ -r "$AXZSH/themes/$1.axzshtheme" ]]; then
+ theme="$AXZSH/themes/$1.axzshtheme"
+ else
+ # Look for theme in specific remote module:
+ for f (
+ "$AXZSH/repos/$1/"*.axzshtheme(N[1])
+ "$AXZSH/repos/$1/"*.zsh-theme(N[1])
+ ); do
+ if [[ -r "$f" ]]; then
+ theme="$f"
+ break
+ fi
+ done
+
+ # Look for theme inside of installed plugins:
+ for dname (
+ "$AXZSH/custom_themes"
+ "$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
+ ax_error "Theme \"$1\" not found!"
+ return 1
+ fi
+ fi
+ ln -fs "$theme" "$link_name" || return 1
+ return $?
+}
+
+function UpgradeAXZSH {
+ if [[ $+commands[git] -eq 0 ]]; then
+ ax_error "The git(1) command is not available!"
+ return 1
+ fi
+ if [[ ! -d "$AXZSH/.git" ]]; then
+ ax_error "AX-ZSH seems not to be installed using Git. Can't upgrade!"
+ return 1
+ fi
+
+ ax_msg - "Upgrading AX-ZSH in \"$AXZSH\" using git(1) ..."
+ (
+ set -e
+ cd "$AXZSH"
+ git pull --ff-only || ax_error "Git pull failed!"
+ git log --pretty=format:"%C(yellow)%h %C(blue)%ar %C(green)%an %Creset%s" ORIG_HEAD..
+ )
+}
+
+function UpgradeForeignPlugins {
+ if [[ $+commands[git] -eq 0 ]]; then
+ ax_error "The git(1) command is not available!"
+ return 1
+ fi
+
+ for dir ($AXZSH/repos/*(N)); do
+ name=${dir:t:s/#/\//}
+ if [[ -d "$dir/.git" ]]; then
+ ax_msg - "Upgrading \"$name\" [git] ..."
+ (
+ set -e
+ cd "$dir"
+ git pull --ff-only || ax_error "Git pull failed!"
+ git log --pretty=format:"%C(yellow)%h %C(blue)%ar %C(green)%an %Creset%s" ORIG_HEAD..
+ )
+ else
+ ax_error "Unknown repository type!"
+ fi
+ done
+}
+
+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\naxzsh_plugin_init()\n{\n" "$p" >>"$T"
+ cat "$p" >>"$T"
+ printf "}\naxzsh_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}
+
+ # Test if plugin is already enabled
+ if [[ -e "$AXZSH/active_plugins/$plugin" ]]; then
+ printf ' \e[1;32m+\e[m "\e[1m%s\e[m" ... ' "${plugin}"
+ enabled=1
+ else
+ printf ' \e[1;31m-\e[m "%s" ... ' "${plugin}"
+ unset enabled
+ fi
+
+ # Test plugin ...
+ new_plugin=""
+ for script ($AXZSH/plugins/$plugin/$plugin.{zshrc,zprofile,ax-io}); do
+ [[ -r "$script" ]] || continue
+ (
+ AXZSH_PLUGIN_CHECK=1
+ source "$T"
+ axzsh_plugin_fnc() { source "$script" }
+ axzsh_plugin_fnc
+ ); r=$?
+ [[ $r -eq 0 ]] && new_plugin=$plugin
+ break
+ done
+ if [[ -n "$new_plugin" ]]; then
+ detected_plugins+=($new_plugin)
+ [[ -n "$enabled" ]] || missing_plugins+=($new_plugin)
+ ax_msg 0 "OK."
+ elif [[ $r -eq 91 ]]; then
+ ax_msg 1 "ignored."
+ elif [[ $r -eq 92 ]]; then
+ ax_msg 1 "optional."
+ else
+ [[ -n "$enabled" ]] && invalid_plugins+=($plugin)
+ ax_msg 2 "failed ($r)."
+ fi
+ done
+ rm -f "$T"
+ echo
+
+ result=0
+ if [[ -n "$missing_plugins" ]]; then
+ ax_msg 1 "Run the following command to enable all missing plugins:"
+ echo "$AXZSH/bin/axzshctl enable-plugin" $missing_plugins
+ echo
+ result=1
+ else
+ ax_msg 0 "All detected plugins are already enabled."
+ fi
+
+ if [[ -n "$invalid_plugins" ]]; then
+ ax_msg 1 "Run the following command to disable all failed plugins:"
+ echo "$AXZSH/bin/axzshctl disable-plugin" $invalid_plugins
+ result=1
+ else
+ ax_msg 0 "No failed plugins are enabled."
+ fi
+
+ echo
+ return $result
+}
+
+NAME="$0:t"