#!/bin/zsh # # AX-ZSH: Alex' Modular ZSH Configuration # Copyright (c) 2015-2016 Alexander Barton # # 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 "Usage: $NAME [...]" echo echo " enable-plugin [ [...]]" echo " Enable plugin(s)." echo echo " disable-plugin [ [...]]" echo " Disable plugin(s)." echo echo " reset-plugins" echo " Reset active plugins to the default set." echo echo " enable-default-plugins" echo " Enable all default plugins." echo echo " set-theme |-" echo " Set active theme to , or to the default." echo echo " upgrade" echo " Upgrade AX-ZSH installation (requires Git)." echo exit 2 } function EnablePlugin { local dir="$AXZSH/active_plugins" if [[ -h "$dir/$1" ]]; then 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" ); do [[ ! -d "$dname" ]] && continue mkdir -p "$dir" ( cd "$dir" || exit 9 ln -sv "$dname" "$PWD" ) return $? done ax_msg 2 "Plugin \"$1\" not found!" return 1 } function DisablePlugin { local dir="$AXZSH/active_plugins" if [[ ! -h "$dir/$1" ]]; then ax_msg 1 "Plugin \"$1\" not active?" return 1 fi rm -v "$dir/$1" return $? } function ResetPlugins { local dir="$AXZSH/active_plugins" if [[ -e "$dir" ]]; then ax_msg - "Removing all symbolic links in $dir ..." find "$dir" -type l -print -delete fi return $? } function EnableDefaultPlugins { local dir="$AXZSH/active_plugins" ax_msg - "Activating (linking) default plugins ..." mkdir -p "$dir" ( cd "$dir" || exit 9 ln -sfv "$AXZSH/default_plugins/"* "$PWD" ) return $? } function SetTheme { local link_name="$AXZSH/active_theme" if [ $# -ne 1 ]; then echo "Usage: axzsh_set_theme " return 1 fi rm -f "$link_name" || return 1 if [ "$1" = "-" ]; then echo "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 echo "Theme \"$1\" not found!" return 1 fi ln -sv "$theme" "$link_name" || return 1 return $? } function UpgradeAXZSH { if [[ $+commands[git] -eq 0 ]]; then ax_msg 2 "The git(1) command is not available!" return 1 fi if [[ ! -d "$AXZSH/.git" ]]; then ax_msg 2 "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 ) } NAME="$0:t" [[ $# -gt 0 ]] || Usage if [[ -z "$AXZSH" || ! -d "$AXZSH" ]]; then ax_msg 2 "Oops, \"AXZSH\" is not set or invalid!" exit 3 fi cmd="$1" shift case "$cmd" in "enable-plugin") [[ $# -gt 0 ]] || Usage for plugin in "$@"; do EnablePlugin "$plugin" done ;; "disable-plugin") [[ $# -gt 0 ]] || Usage for plugin in "$@"; do DisablePlugin "$plugin" done ;; "reset-plugins") [[ $# -eq 0 ]] || Usage ResetPlugins EnableDefaultPlugins ;; "enable-default-plugins") [[ $# -eq 0 ]] || Usage EnableDefaultPlugins ;; "set-theme") [[ $# -eq 1 ]] || Usage SetTheme "$1" ;; "upgrade") [[ $# -eq 0 ]] || Usage UpgradeAXZSH ;; *) Usage esac