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 echo "$1" | sed -e 's|/|#|g'
53 function EnablePlugin {
54 local plugin=$(NormalizedPluginName "$1")
55 local dir="$AXZSH/active_plugins"
57 if [[ -h "$dir/$plugin" ]]; then
58 ax_msg 1 "Plugin \"$1\" already active!"
62 if [[ "$1" =~ "/" ]]; then
64 mkdir -p "$AXZSH/repos"
65 if [[ ! -e "$AXZSH/repos/$plugin" ]]; then
66 ax_msg - "Cloning plugin from GitHub ..."
67 git clone "https://github.com/$1.git" \
68 "$AXZSH/repos/$plugin"
74 "$AXZSH_PLUGIN_D/$plugin"
76 "$AXZSH/custom_plugins/$plugin"
77 "$AXZSH/repos/$plugin"
78 "$AXZSH/plugins/$plugin"
79 "$AXZSH/default_plugins/$plugin"
82 [[ ! -d "$dname" ]] && continue
86 ln -sv "$dname" "$PWD"
91 ax_msg 2 "Plugin \"$1\" not found!"
95 function DisablePlugin {
96 local plugin=$(NormalizedPluginName "$1")
97 local dir="$AXZSH/active_plugins"
99 if [[ ! -h "$dir/$plugin" ]]; then
100 ax_msg 1 "Plugin \"$1\" not active?"
104 rm -v "$dir/$plugin"; r=$?
105 [ $r -eq 0 ] && rm -fr "$AXZSH/repos/$plugin"
109 function ResetPlugins {
110 local dir="$AXZSH/active_plugins"
112 if [[ -e "$dir" ]]; then
113 ax_msg - "Removing all symbolic links in $dir ..."
114 find "$dir" -type l -print -delete
119 function EnableDefaultPlugins {
120 local dir="$AXZSH/active_plugins"
122 ax_msg - "Activating (linking) default plugins ..."
126 ln -sfv "$AXZSH/default_plugins/"* "$PWD"
132 local link_name="$AXZSH/active_theme"
134 if [ $# -ne 1 ]; then
135 echo "Usage: axzsh_set_theme <name|->"
139 rm -f "$link_name" || return 1
141 if [ "$1" = "-" ]; then
142 echo "Theme settings have been reset."
148 elif [ -r "$AXZSH/custom_themes/$1.axzshtheme" ]; then
149 theme="$AXZSH/custom_themes/$1.axzshtheme"
150 elif [ -r "$AXZSH/themes/$1.axzshtheme" ]; then
151 theme="$AXZSH/themes/$1.axzshtheme"
153 echo "Theme \"$1\" not found!"
156 ln -sv "$theme" "$link_name" || return 1
160 function UpgradeAXZSH {
161 if [[ $+commands[git] -eq 0 ]]; then
162 ax_msg 2 "The git(1) command is not available!"
165 if [[ ! -d "$AXZSH/.git" ]]; then
166 ax_msg 2 "AX-ZSH seems not to be installed using Git. Can't upgrade!"
170 ax_msg - "Upgrading AX-ZSH in \"$AXZSH\" using git(1) ..."
171 ( cd "$AXZSH" && git pull --ff-only )
174 function UpgradeForeignPlugins {
175 if [[ $+commands[git] -eq 0 ]]; then
176 ax_msg 2 "The git(1) command is not available!"
180 for dir ($AXZSH/repos/*(N)); do
181 name=$(basename "$dir" | sed -e 's|#|/|g')
182 if [ -d "$dir/.git" ]; then
183 ax_msg - "Upgrading \"$name\" [git] ..."
186 git pull --ff-only || ax_msg 2 "Pull failed!"
189 ax_msg 2 "Unknown repository type!"
196 [[ $# -gt 0 ]] || Usage
198 if [[ -z "$AXZSH" || ! -d "$AXZSH" ]]; then
199 ax_msg 2 "Oops, \"AXZSH\" is not set or invalid!"
208 [[ $# -gt 0 ]] || Usage
209 for plugin in "$@"; do
210 EnablePlugin "$plugin"
214 [[ $# -gt 0 ]] || Usage
215 for plugin in "$@"; do
216 DisablePlugin "$plugin"
220 [[ $# -eq 0 ]] || Usage
224 "enable-default-plugins")
225 [[ $# -eq 0 ]] || Usage
229 [[ $# -eq 1 ]] || Usage
233 [[ $# -eq 0 ]] || Usage
235 UpgradeForeignPlugins