Commit 4b8d7db1f11346b5c97e2de562799b936b79a3b8
1 parent
6a4fbde8d5
Remove ugly message when installing bundles.
This message comes up every time you switch the prompt theme.
Showing 1 changed file with 0 additions and 1 deletions Inline Diff
antigen.zsh
1 | #!/bin/zsh | 1 | #!/bin/zsh |
2 | 2 | ||
3 | # Each line in this string has the following entries separated by a space | 3 | # Each line in this string has the following entries separated by a space |
4 | # character. | 4 | # character. |
5 | # <bundle-name>, <repo-url>, <plugin-location>, <repo-local-clone-dir> | 5 | # <bundle-name>, <repo-url>, <plugin-location>, <repo-local-clone-dir> |
6 | # FIXME: Is not kept local by zsh! | 6 | # FIXME: Is not kept local by zsh! |
7 | local bundles="" | 7 | local bundles="" |
8 | 8 | ||
9 | # Syntaxes | 9 | # Syntaxes |
10 | # bundle <url> [<loc>=/] [<name>] | 10 | # bundle <url> [<loc>=/] [<name>] |
11 | bundle () { | 11 | bundle () { |
12 | 12 | ||
13 | # Bundle spec arguments' default values. | 13 | # Bundle spec arguments' default values. |
14 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 14 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
15 | local loc=/ | 15 | local loc=/ |
16 | local name= | 16 | local name= |
17 | local load=true | 17 | local load=true |
18 | 18 | ||
19 | # Set spec values based on the positional arguments. | 19 | # Set spec values based on the positional arguments. |
20 | local position_args='url loc name' | 20 | local position_args='url loc name' |
21 | local i=1 | 21 | local i=1 |
22 | while ! [[ -z $1 || $1 == --*=* ]]; do | 22 | while ! [[ -z $1 || $1 == --*=* ]]; do |
23 | arg_name="$(echo "$position_args" | cut -d\ -f$i)" | 23 | arg_name="$(echo "$position_args" | cut -d\ -f$i)" |
24 | arg_value="$1" | 24 | arg_value="$1" |
25 | eval "local $arg_name='$arg_value'" | 25 | eval "local $arg_name='$arg_value'" |
26 | shift | 26 | shift |
27 | i=$(($i + 1)) | 27 | i=$(($i + 1)) |
28 | done | 28 | done |
29 | 29 | ||
30 | # Check if url is just the plugin name. Super short syntax. | 30 | # Check if url is just the plugin name. Super short syntax. |
31 | if [[ "$url" != */* ]]; then | 31 | if [[ "$url" != */* ]]; then |
32 | loc="plugins/$url" | 32 | loc="plugins/$url" |
33 | url="$ANTIGEN_DEFAULT_REPO_URL" | 33 | url="$ANTIGEN_DEFAULT_REPO_URL" |
34 | fi | 34 | fi |
35 | 35 | ||
36 | # Set spec values from keyword arguments, if any. The remaining arguments | 36 | # Set spec values from keyword arguments, if any. The remaining arguments |
37 | # are all assumed to be keyword arguments. | 37 | # are all assumed to be keyword arguments. |
38 | while [[ $1 == --*=* ]]; do | 38 | while [[ $1 == --*=* ]]; do |
39 | arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" | 39 | arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" |
40 | arg_value="$(echo "$1" | cut -d= -f2)" | 40 | arg_value="$(echo "$1" | cut -d= -f2)" |
41 | eval "local $arg_name='$arg_value'" | 41 | eval "local $arg_name='$arg_value'" |
42 | shift | 42 | shift |
43 | done | 43 | done |
44 | 44 | ||
45 | # Resolve the url. | 45 | # Resolve the url. |
46 | if [[ $url != git://* && $url != https://* ]]; then | 46 | if [[ $url != git://* && $url != https://* ]]; then |
47 | url="${url%.git}" | 47 | url="${url%.git}" |
48 | name="$(basename "$url")" | 48 | name="$(basename "$url")" |
49 | url="https://github.com/$url.git" | 49 | url="https://github.com/$url.git" |
50 | fi | 50 | fi |
51 | 51 | ||
52 | # Plugin's repo will be cloned here. | 52 | # Plugin's repo will be cloned here. |
53 | local clone_dir="$ANTIGEN_REPO_CACHE/$(echo "$url" \ | 53 | local clone_dir="$ANTIGEN_REPO_CACHE/$(echo "$url" \ |
54 | | sed -e 's/\.git$//' -e 's./.-SLASH-.g' -e 's.:.-COLON-.g')" | 54 | | sed -e 's/\.git$//' -e 's./.-SLASH-.g' -e 's.:.-COLON-.g')" |
55 | 55 | ||
56 | # Make an intelligent guess about the name of the plugin, if not already | 56 | # Make an intelligent guess about the name of the plugin, if not already |
57 | # done or is explicitly specified. | 57 | # done or is explicitly specified. |
58 | if [[ -z $name ]]; then | 58 | if [[ -z $name ]]; then |
59 | name="$(basename $url/$loc)" | 59 | name="$(basename $url/$loc)" |
60 | fi | 60 | fi |
61 | 61 | ||
62 | # Add it to the record. | 62 | # Add it to the record. |
63 | bundles="$bundles\n$name $url $loc $clone_dir" | 63 | bundles="$bundles\n$name $url $loc $clone_dir" |
64 | 64 | ||
65 | # Load it, unless specified otherwise. | 65 | # Load it, unless specified otherwise. |
66 | if $load; then | 66 | if $load; then |
67 | bundle-load "$name" | 67 | bundle-load "$name" |
68 | fi | 68 | fi |
69 | } | 69 | } |
70 | 70 | ||
71 | bundle-install () { | 71 | bundle-install () { |
72 | 72 | ||
73 | if [[ $1 == --update ]]; then | 73 | if [[ $1 == --update ]]; then |
74 | local update=true | 74 | local update=true |
75 | shift | 75 | shift |
76 | else | 76 | else |
77 | local update=false | 77 | local update=false |
78 | fi | 78 | fi |
79 | 79 | ||
80 | mkdir -p "$ANTIGEN_BUNDLE_DIR" | 80 | mkdir -p "$ANTIGEN_BUNDLE_DIR" |
81 | 81 | ||
82 | local handled_repos="" | 82 | local handled_repos="" |
83 | 83 | ||
84 | if [[ $# != 0 ]]; then | 84 | if [[ $# != 0 ]]; then |
85 | # Record and install just the given plugin here and now. | 85 | # Record and install just the given plugin here and now. |
86 | bundle "$@" | 86 | bundle "$@" |
87 | echo "$bundles" | tail -1 | 87 | echo "$bundles" | tail -1 |
88 | 88 | ||
89 | else | 89 | else |
90 | # Install all the plugins, previously recorded. | 90 | # Install all the plugins, previously recorded. |
91 | echo-non-empty "$bundles" | 91 | echo-non-empty "$bundles" |
92 | 92 | ||
93 | fi | while read spec; do | 93 | fi | while read spec; do |
94 | echo "-> $spec" | ||
95 | 94 | ||
96 | local name="$(echo "$spec" | awk '{print $1}')" | 95 | local name="$(echo "$spec" | awk '{print $1}')" |
97 | local url="$(echo "$spec" | awk '{print $2}')" | 96 | local url="$(echo "$spec" | awk '{print $2}')" |
98 | local loc="$(echo "$spec" | awk '{print $3}')" | 97 | local loc="$(echo "$spec" | awk '{print $3}')" |
99 | local clone_dir="$(echo "$spec" | awk '{print $4}')" | 98 | local clone_dir="$(echo "$spec" | awk '{print $4}')" |
100 | 99 | ||
101 | if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then | 100 | if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then |
102 | if [[ ! -d $clone_dir ]]; then | 101 | if [[ ! -d $clone_dir ]]; then |
103 | git clone "$url" "$clone_dir" | 102 | git clone "$url" "$clone_dir" |
104 | elif $update; then | 103 | elif $update; then |
105 | git --git-dir "$clone_dir/.git" pull | 104 | git --git-dir "$clone_dir/.git" pull |
106 | fi | 105 | fi |
107 | 106 | ||
108 | handled_repos="$handled_repos\n$url" | 107 | handled_repos="$handled_repos\n$url" |
109 | fi | 108 | fi |
110 | 109 | ||
111 | if [[ $name != *.theme ]]; then | 110 | if [[ $name != *.theme ]]; then |
112 | echo Installing $name | 111 | echo Installing $name |
113 | local bundle_dest="$ANTIGEN_BUNDLE_DIR/$name" | 112 | local bundle_dest="$ANTIGEN_BUNDLE_DIR/$name" |
114 | test -e "$bundle_dest" && rm -rf "$bundle_dest" | 113 | test -e "$bundle_dest" && rm -rf "$bundle_dest" |
115 | ln -s "$clone_dir/$loc" "$bundle_dest" | 114 | ln -s "$clone_dir/$loc" "$bundle_dest" |
116 | else | 115 | else |
117 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" | 116 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" |
118 | cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" | 117 | cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" |
119 | fi | 118 | fi |
120 | 119 | ||
121 | bundle-load "$name" | 120 | bundle-load "$name" |
122 | 121 | ||
123 | done | 122 | done |
124 | 123 | ||
125 | # Initialize completions after installing | 124 | # Initialize completions after installing |
126 | bundle-apply | 125 | bundle-apply |
127 | 126 | ||
128 | } | 127 | } |
129 | 128 | ||
130 | bundle-install! () { | 129 | bundle-install! () { |
131 | bundle-install --update | 130 | bundle-install --update |
132 | } | 131 | } |
133 | 132 | ||
134 | bundle-cleanup () { | 133 | bundle-cleanup () { |
135 | 134 | ||
136 | # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. | 135 | # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. |
137 | local unidentified_bundles="$(comm -13 \ | 136 | local unidentified_bundles="$(comm -13 \ |
138 | <(echo-non-empty "$bundles" | awk '{print $1}' | sort) \ | 137 | <(echo-non-empty "$bundles" | awk '{print $1}' | sort) \ |
139 | <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" | 138 | <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" |
140 | 139 | ||
141 | if [[ -z $unidentified_bundles ]]; then | 140 | if [[ -z $unidentified_bundles ]]; then |
142 | echo "You don't have any unidentified bundles." | 141 | echo "You don't have any unidentified bundles." |
143 | return 0 | 142 | return 0 |
144 | fi | 143 | fi |
145 | 144 | ||
146 | echo The following bundles are not recorded: | 145 | echo The following bundles are not recorded: |
147 | echo "$unidentified_bundles" | sed 's/^/ /' | 146 | echo "$unidentified_bundles" | sed 's/^/ /' |
148 | 147 | ||
149 | echo -n '\nDelete them all? [y/N] ' | 148 | echo -n '\nDelete them all? [y/N] ' |
150 | if read -q; then | 149 | if read -q; then |
151 | echo | 150 | echo |
152 | echo | 151 | echo |
153 | echo "$unidentified_bundles" | while read name; do | 152 | echo "$unidentified_bundles" | while read name; do |
154 | echo -n Deleting $name... | 153 | echo -n Deleting $name... |
155 | rm -rf "$ANTIGEN_BUNDLE_DIR/$name" | 154 | rm -rf "$ANTIGEN_BUNDLE_DIR/$name" |
156 | echo ' done.' | 155 | echo ' done.' |
157 | done | 156 | done |
158 | else | 157 | else |
159 | echo | 158 | echo |
160 | echo Nothing deleted. | 159 | echo Nothing deleted. |
161 | fi | 160 | fi |
162 | } | 161 | } |
163 | 162 | ||
164 | bundle-load () { | 163 | bundle-load () { |
165 | if [[ $1 == --init ]]; then | 164 | if [[ $1 == --init ]]; then |
166 | do_init=true | 165 | do_init=true |
167 | shift | 166 | shift |
168 | else | 167 | else |
169 | do_init=false | 168 | do_init=false |
170 | fi | 169 | fi |
171 | 170 | ||
172 | name="$1" | 171 | name="$1" |
173 | bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" | 172 | bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" |
174 | 173 | ||
175 | # Source the plugin script | 174 | # Source the plugin script |
176 | script_loc="$bundle_dir/$name.plugin.zsh" | 175 | script_loc="$bundle_dir/$name.plugin.zsh" |
177 | if [[ -f $script_loc ]]; then | 176 | if [[ -f $script_loc ]]; then |
178 | source "$script_loc" | 177 | source "$script_loc" |
179 | fi | 178 | fi |
180 | 179 | ||
181 | # If the name of the plugin ends with `.lib`, all the *.zsh files in it are | 180 | # If the name of the plugin ends with `.lib`, all the *.zsh files in it are |
182 | # sourced. This is kind of a hack to source the libraries of oh-my-zsh. | 181 | # sourced. This is kind of a hack to source the libraries of oh-my-zsh. |
183 | if [[ $name == *.lib ]]; then | 182 | if [[ $name == *.lib ]]; then |
184 | # FIXME: This throws an error if no files match the given glob pattern. | 183 | # FIXME: This throws an error if no files match the given glob pattern. |
185 | for lib ($bundle_dir/*.zsh) source $lib | 184 | for lib ($bundle_dir/*.zsh) source $lib |
186 | fi | 185 | fi |
187 | 186 | ||
188 | # If the name ends with `.theme`, it is handled as if it were a zsh-theme | 187 | # If the name ends with `.theme`, it is handled as if it were a zsh-theme |
189 | # plugin. | 188 | # plugin. |
190 | if [[ $name == *.theme ]]; then | 189 | if [[ $name == *.theme ]]; then |
191 | local theme_file="$bundle_dir/${name%.theme}.zsh-theme" | 190 | local theme_file="$bundle_dir/${name%.theme}.zsh-theme" |
192 | test -f "$theme_file" && source "$theme_file" | 191 | test -f "$theme_file" && source "$theme_file" |
193 | fi | 192 | fi |
194 | 193 | ||
195 | # Add to $fpath, for completion(s) | 194 | # Add to $fpath, for completion(s) |
196 | fpath=($bundle_dir $fpath) | 195 | fpath=($bundle_dir $fpath) |
197 | 196 | ||
198 | if $do_init; then | 197 | if $do_init; then |
199 | bundle-init | 198 | bundle-init |
200 | fi | 199 | fi |
201 | } | 200 | } |
202 | 201 | ||
203 | bundle-lib () { | 202 | bundle-lib () { |
204 | bundle --name=oh-my-zsh.lib --loc=lib | 203 | bundle --name=oh-my-zsh.lib --loc=lib |
205 | } | 204 | } |
206 | 205 | ||
207 | bundle-theme () { | 206 | bundle-theme () { |
208 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 207 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
209 | local name="${1:-robbyrussell}" | 208 | local name="${1:-robbyrussell}" |
210 | bundle-install "$url" --name=$name.theme --loc=themes/$name.zsh-theme | 209 | bundle-install "$url" --name=$name.theme --loc=themes/$name.zsh-theme |
211 | } | 210 | } |
212 | 211 | ||
213 | bundle-apply () { | 212 | bundle-apply () { |
214 | # Initialize completion. | 213 | # Initialize completion. |
215 | compinit -i | 214 | compinit -i |
216 | } | 215 | } |
217 | 216 | ||
218 | # Does what it says. | 217 | # Does what it says. |
219 | echo-non-empty () { | 218 | echo-non-empty () { |
220 | echo "$@" | while read line; do | 219 | echo "$@" | while read line; do |
221 | [[ $line != "" ]] && echo $line | 220 | [[ $line != "" ]] && echo $line |
222 | done | 221 | done |
223 | } | 222 | } |
224 | 223 | ||
225 | -bundle-env-setup () { | 224 | -bundle-env-setup () { |
226 | # Pre-startup initializations | 225 | # Pre-startup initializations |
227 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 226 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
228 | https://github.com/robbyrussell/oh-my-zsh.git | 227 | https://github.com/robbyrussell/oh-my-zsh.git |
229 | -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache | 228 | -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache |
230 | -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles | 229 | -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles |
231 | 230 | ||
232 | # Load the compinit module | 231 | # Load the compinit module |
233 | autoload -U compinit | 232 | autoload -U compinit |
234 | 233 | ||
235 | # Without the following, `compdef` function is not defined. | 234 | # Without the following, `compdef` function is not defined. |
236 | compinit -i | 235 | compinit -i |
237 | } | 236 | } |
238 | 237 | ||
239 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is | 238 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is |
240 | # not already set. | 239 | # not already set. |
241 | -set-default () { | 240 | -set-default () { |
242 | arg_name="$1" | 241 | arg_name="$1" |
243 | arg_value="$2" | 242 | arg_value="$2" |
244 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 243 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
245 | } | 244 | } |
246 | 245 | ||
247 | -bundle-env-setup | 246 | -bundle-env-setup |
248 | 247 |