+function SetTheme {
+ local link_name="$AXZSH/active_theme"
+
+ 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 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 -fsv "$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) ..."
+ ( cd "$AXZSH" && git pull --ff-only )
+}
+
+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] ..."
+ (
+ cd "$dir"
+ git pull --ff-only || ax_error "Pull failed!"
+ )
+ else
+ ax_error "Unknown repository type!"
+ fi
+ done
+}
+
+function CheckPlugins {
+ missing_plugins=()
+ invalid_plugins=()
+
+ ax_msg - "Checking plugins ..."
+ for dir ($AXZSH/plugins/*(N)); do
+ plugin=${dir:t}
+
+ # Test if plugin is already enabled
+ [[ -e "$AXZSH/active_plugins/$plugin" ]] \
+ && enabled=" (enabled)" \
+ || unset enabled
+
+ # Test plugin ...
+ printf " - \"%s\"%s ... " "$plugin" "$enabled"
+ new_plugin=""
+ for script ($AXZSH/plugins/$plugin/$plugin.{zshrc,zprofile}); do
+ [[ -r "$script" ]] || continue
+ AXZSH_PLUGIN_CHECK=1 zsh -i -c "source $script"; r=$?
+ if [[ $r -eq 0 ]]; then
+ new_plugin=$plugin
+ break
+ fi
+ 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."
+ fi
+ done
+ 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"