3 # AX-ZSH: Alex' Modular ZSH Configuration
4 # Copyright (c) 2015-2016 Alexander Barton <alex@barton.de>
7 # Include "ax-common.sh", if available:
8 for dir ("$HOME/lib" "$HOME/.ax" /usr/local /opt/ax /usr); do
9 [[ -z "$ax_common_sourced" ]] || break
10 ax_common="${dir}/lib/ax/ax-common.sh"
11 [[ -r "$ax_common" ]] && source "$ax_common"
13 if [[ -z "$ax_common_sourced" ]]; then
16 "1"|"2") echo -n "! "; ;;
23 unset dir ax_common ax_common_sourced
26 echo "Usage: $NAME <command> [...]"
28 echo " enable-plugin <name|directory> [<name|directory> [...]]"
29 echo " Enable plugin(s)."
31 echo " disable-plugin <name> [<name> [...]]"
32 echo " Disable plugin(s)."
35 echo " Reset active plugins to the default set."
37 echo " enable-default-plugins"
38 echo " Enable all default plugins."
40 echo " set-theme <name>|-"
41 echo " Set active theme to <name>, or to the default."
44 echo " Upgrade AX-ZSH installation (requires Git)."
49 function NormalizedPluginName {
50 if [[ "$1" =~ "^[[:alnum:]-]+/[[:alnum:]_-]+$" ]]; then
51 echo "$1" | sed -e 's|/|#|g'
52 elif [[ "$1" =~ "/" ]]; then
59 function EnablePlugin {
60 local plugin=$(NormalizedPluginName "$1")
61 local dir="$AXZSH/active_plugins"
63 if [[ -h "$dir/$plugin" ]]; then
64 ax_msg 1 "Plugin \"$1\" already active!"
68 if [[ "$1" =~ "^[[:alnum:]-]+/[[:alnum:]_-]+$" ]]; then
70 mkdir -p "$AXZSH/repos"
71 if [[ ! -e "$AXZSH/repos/$plugin" ]]; then
72 ax_msg - "Cloning plugin from GitHub ..."
73 git clone "https://github.com/$1.git" \
74 "$AXZSH/repos/$plugin"
80 "$AXZSH_PLUGIN_D/$plugin"
82 "$AXZSH/custom_plugins/$plugin"
83 "$AXZSH/repos/$plugin"
84 "$AXZSH/plugins/$plugin"
85 "$AXZSH/default_plugins/$plugin"
88 [[ ! -d "$dname" ]] && continue
92 ln -sv "$dname" "$PWD"
97 ax_msg 2 "Plugin \"$1\" not found!"
101 function DisablePlugin {
102 local plugin=$(NormalizedPluginName "$1")
103 local dir="$AXZSH/active_plugins"
105 if [[ ! -h "$dir/$plugin" ]]; then
106 ax_msg 1 "Plugin \"$1\" not active?"
110 rm -v "$dir/$plugin"; r=$?
111 [ $r -eq 0 ] && rm -fr "$AXZSH/repos/$plugin"
115 function ResetPlugins {
116 local dir="$AXZSH/active_plugins"
119 if [[ -e "$dir" ]]; then
120 ax_msg - "Removing all symbolic links in $dir ..."
121 find "$dir" -type l -print -delete; r1=$?
124 ax_msg - "Removing all external repositories in \"$AXZSH/repos\" ..."
125 rm -fr "$AXZSH/repos"; r2=$?
127 [[ $r1 == 0 && $r2 == 0 ]] && return 0 || return 1
130 function EnableDefaultPlugins {
131 local dir="$AXZSH/active_plugins"
133 ax_msg - "Activating (linking) default plugins ..."
137 ln -sfv "$AXZSH/default_plugins/"* "$PWD"
143 local link_name="$AXZSH/active_theme"
145 if [ $# -ne 1 ]; then
146 echo "Usage: axzsh_set_theme <name|->"
150 rm -f "$link_name" || return 1
152 if [ "$1" = "-" ]; then
153 echo "Theme settings have been reset."
159 elif [ -r "$AXZSH/custom_themes/$1.axzshtheme" ]; then
160 theme="$AXZSH/custom_themes/$1.axzshtheme"
161 elif [ -r "$AXZSH/themes/$1.axzshtheme" ]; then
162 theme="$AXZSH/themes/$1.axzshtheme"
164 echo "Theme \"$1\" not found!"
167 ln -sv "$theme" "$link_name" || return 1
171 function UpgradeAXZSH {
172 if [[ $+commands[git] -eq 0 ]]; then
173 ax_msg 2 "The git(1) command is not available!"
176 if [[ ! -d "$AXZSH/.git" ]]; then
177 ax_msg 2 "AX-ZSH seems not to be installed using Git. Can't upgrade!"
181 ax_msg - "Upgrading AX-ZSH in \"$AXZSH\" using git(1) ..."
182 ( cd "$AXZSH" && git pull --ff-only )
185 function UpgradeForeignPlugins {
186 if [[ $+commands[git] -eq 0 ]]; then
187 ax_msg 2 "The git(1) command is not available!"
191 for dir ($AXZSH/repos/*(N)); do
192 name=$(basename "$dir" | sed -e 's|#|/|g')
193 if [ -d "$dir/.git" ]; then
194 ax_msg - "Upgrading \"$name\" [git] ..."
197 git pull --ff-only || ax_msg 2 "Pull failed!"
200 ax_msg 2 "Unknown repository type!"
207 [[ $# -gt 0 ]] || Usage
209 if [[ -z "$AXZSH" || ! -d "$AXZSH" ]]; then
210 ax_msg 2 "Oops, \"AXZSH\" is not set or invalid!"
219 [[ $# -gt 0 ]] || Usage
220 for plugin in "$@"; do
221 EnablePlugin "$plugin"
225 [[ $# -gt 0 ]] || Usage
226 for plugin in "$@"; do
227 DisablePlugin "$plugin"
231 [[ $# -eq 0 ]] || Usage
235 "enable-default-plugins")
236 [[ $# -eq 0 ]] || Usage
240 [[ $# -eq 1 ]] || Usage
244 [[ $# -eq 0 ]] || Usage
246 UpgradeForeignPlugins