Commit a9ebdcdbec77e261ead63f7d326b3fb0791d170c
1 parent
a8ea6fb494
Don't load compinit module at startup.
Kills the whole purpose of the compdef deferrer function introduced in #37. Completions are now correctly deferred and applied when `antigen-apply` is called.
Showing 1 changed file with 15 additions and 11 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 | # <repo-url>, <plugin-location>, <bundle-type>, <has-local-clone> | 5 | # <repo-url>, <plugin-location>, <bundle-type>, <has-local-clone> |
6 | # FIXME: Is not kept local by zsh! | 6 | # FIXME: Is not kept local by zsh! |
7 | local _ANTIGEN_BUNDLE_RECORD="" | 7 | local _ANTIGEN_BUNDLE_RECORD="" |
8 | local _ANTIGEN_INSTALL_DIR="$(dirname $0)" | 8 | local _ANTIGEN_INSTALL_DIR="$(dirname $0)" |
9 | 9 | ||
10 | # Used to defer compinit/compdef | 10 | # Used to defer compinit/compdef |
11 | typeset -a __deferred_compdefs | 11 | typeset -a __deferred_compdefs |
12 | compdef () { __deferred_compdefs=(${__deferred_compdefs} "${*}") } | 12 | compdef () { __deferred_compdefs=($__deferred_compdefs "$*") } |
13 | 13 | ||
14 | # Syntaxes | 14 | # Syntaxes |
15 | # antigen-bundle <url> [<loc>=/] | 15 | # antigen-bundle <url> [<loc>=/] |
16 | # Keyword only arguments: | 16 | # Keyword only arguments: |
17 | # branch - The branch of the repo to use for this bundle. | 17 | # branch - The branch of the repo to use for this bundle. |
18 | antigen-bundle () { | 18 | antigen-bundle () { |
19 | 19 | ||
20 | # Bundle spec arguments' default values. | 20 | # Bundle spec arguments' default values. |
21 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 21 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
22 | local loc=/ | 22 | local loc=/ |
23 | local branch= | 23 | local branch= |
24 | local no_local_clone=false | 24 | local no_local_clone=false |
25 | local btype=plugin | 25 | local btype=plugin |
26 | 26 | ||
27 | # Parse the given arguments. (Will overwrite the above values). | 27 | # Parse the given arguments. (Will overwrite the above values). |
28 | eval "$(-antigen-parse-args \ | 28 | eval "$(-antigen-parse-args \ |
29 | 'url?, loc? ; branch:?, no-local-clone?, btype:?' \ | 29 | 'url?, loc? ; branch:?, no-local-clone?, btype:?' \ |
30 | "$@")" | 30 | "$@")" |
31 | 31 | ||
32 | # Check if url is just the plugin name. Super short syntax. | 32 | # Check if url is just the plugin name. Super short syntax. |
33 | if [[ "$url" != */* ]]; then | 33 | if [[ "$url" != */* ]]; then |
34 | loc="plugins/$url" | 34 | loc="plugins/$url" |
35 | url="$ANTIGEN_DEFAULT_REPO_URL" | 35 | url="$ANTIGEN_DEFAULT_REPO_URL" |
36 | fi | 36 | fi |
37 | 37 | ||
38 | # Resolve the url. | 38 | # Resolve the url. |
39 | url="$(-antigen-resolve-bundle-url "$url")" | 39 | url="$(-antigen-resolve-bundle-url "$url")" |
40 | 40 | ||
41 | # Add the branch information to the url. | 41 | # Add the branch information to the url. |
42 | if [[ ! -z $branch ]]; then | 42 | if [[ ! -z $branch ]]; then |
43 | url="$url|$branch" | 43 | url="$url|$branch" |
44 | fi | 44 | fi |
45 | 45 | ||
46 | # The `make_local_clone` variable better represents whether there should be | 46 | # The `make_local_clone` variable better represents whether there should be |
47 | # a local clone made. For cloning to be avoided, firstly, the `$url` should | 47 | # a local clone made. For cloning to be avoided, firstly, the `$url` should |
48 | # be an absolute local path and `$branch` should be empty. In addition to | 48 | # be an absolute local path and `$branch` should be empty. In addition to |
49 | # these two conditions, either the `--no-local-clone` option should be | 49 | # these two conditions, either the `--no-local-clone` option should be |
50 | # given, or `$url` should not a git repo. | 50 | # given, or `$url` should not a git repo. |
51 | local make_local_clone=true | 51 | local make_local_clone=true |
52 | if [[ $url == /* && -z $branch && | 52 | if [[ $url == /* && -z $branch && |
53 | ( $no_local_clone == true || ! -d $url/.git ) ]]; then | 53 | ( $no_local_clone == true || ! -d $url/.git ) ]]; then |
54 | make_local_clone=false | 54 | make_local_clone=false |
55 | fi | 55 | fi |
56 | 56 | ||
57 | # Add the theme extension to `loc`, if this is a theme. | 57 | # Add the theme extension to `loc`, if this is a theme. |
58 | if [[ $btype == theme && $loc != *.zsh-theme ]]; then | 58 | if [[ $btype == theme && $loc != *.zsh-theme ]]; then |
59 | loc="$loc.zsh-theme" | 59 | loc="$loc.zsh-theme" |
60 | fi | 60 | fi |
61 | 61 | ||
62 | # Add it to the record. | 62 | # Add it to the record. |
63 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" | 63 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" |
64 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD $make_local_clone" | 64 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD $make_local_clone" |
65 | 65 | ||
66 | # Ensure a clone exists for this repo, if needed. | 66 | # Ensure a clone exists for this repo, if needed. |
67 | if $make_local_clone; then | 67 | if $make_local_clone; then |
68 | -antigen-ensure-repo "$url" | 68 | -antigen-ensure-repo "$url" |
69 | fi | 69 | fi |
70 | 70 | ||
71 | # Load the plugin. | 71 | # Load the plugin. |
72 | -antigen-load "$url" "$loc" "$btype" "$make_local_clone" | 72 | -antigen-load "$url" "$loc" "$btype" "$make_local_clone" |
73 | 73 | ||
74 | } | 74 | } |
75 | 75 | ||
76 | -antigen-resolve-bundle-url () { | 76 | -antigen-resolve-bundle-url () { |
77 | # Given an acceptable short/full form of a bundle's repo url, this function | 77 | # Given an acceptable short/full form of a bundle's repo url, this function |
78 | # echoes the full form of the repo's clone url. | 78 | # echoes the full form of the repo's clone url. |
79 | 79 | ||
80 | local url="$1" | 80 | local url="$1" |
81 | 81 | ||
82 | # Expand short github url syntax: `username/reponame`. | 82 | # Expand short github url syntax: `username/reponame`. |
83 | if [[ $url != git://* && | 83 | if [[ $url != git://* && |
84 | $url != https://* && | 84 | $url != https://* && |
85 | $url != /* && | 85 | $url != /* && |
86 | $url != git@github.com:*/* | 86 | $url != git@github.com:*/* |
87 | ]]; then | 87 | ]]; then |
88 | url="https://github.com/${url%.git}.git" | 88 | url="https://github.com/${url%.git}.git" |
89 | fi | 89 | fi |
90 | 90 | ||
91 | echo "$url" | 91 | echo "$url" |
92 | } | 92 | } |
93 | 93 | ||
94 | antigen-bundles () { | 94 | antigen-bundles () { |
95 | # Bulk add many bundles at one go. Empty lines and lines starting with a `#` | 95 | # Bulk add many bundles at one go. Empty lines and lines starting with a `#` |
96 | # are ignored. Everything else is given to `antigen-bundle` as is, no | 96 | # are ignored. Everything else is given to `antigen-bundle` as is, no |
97 | # quoting rules applied. | 97 | # quoting rules applied. |
98 | 98 | ||
99 | local line | 99 | local line |
100 | 100 | ||
101 | grep -v '^\s*$\|^#' | while read line; do | 101 | grep -v '^\s*$\|^#' | while read line; do |
102 | # Using `eval` so that we can use the shell-style quoting in each line | 102 | # Using `eval` so that we can use the shell-style quoting in each line |
103 | # piped to `antigen-bundles`. | 103 | # piped to `antigen-bundles`. |
104 | eval "antigen-bundle $line" | 104 | eval "antigen-bundle $line" |
105 | done | 105 | done |
106 | } | 106 | } |
107 | 107 | ||
108 | antigen-update () { | 108 | antigen-update () { |
109 | # Update your bundles, i.e., `git pull` in all the plugin repos. | 109 | # Update your bundles, i.e., `git pull` in all the plugin repos. |
110 | 110 | ||
111 | date > $ADOTDIR/revert-info | 111 | date > $ADOTDIR/revert-info |
112 | 112 | ||
113 | -antigen-echo-record | | 113 | -antigen-echo-record | |
114 | awk '$4 == "true" {print $1}' | | 114 | awk '$4 == "true" {print $1}' | |
115 | sort -u | | 115 | sort -u | |
116 | while read url; do | 116 | while read url; do |
117 | echo "**** Pulling $url" | 117 | echo "**** Pulling $url" |
118 | 118 | ||
119 | local clone_dir="$(-antigen-get-clone-dir "$url")" | 119 | local clone_dir="$(-antigen-get-clone-dir "$url")" |
120 | if [[ -d "$clone_dir" ]]; then | 120 | if [[ -d "$clone_dir" ]]; then |
121 | (echo -n "$clone_dir:" | 121 | (echo -n "$clone_dir:" |
122 | cd "$clone_dir" | 122 | cd "$clone_dir" |
123 | git rev-parse HEAD) >> $ADOTDIR/revert-info | 123 | git rev-parse HEAD) >> $ADOTDIR/revert-info |
124 | fi | 124 | fi |
125 | 125 | ||
126 | -antigen-ensure-repo "$url" --update --verbose | 126 | -antigen-ensure-repo "$url" --update --verbose |
127 | 127 | ||
128 | echo | 128 | echo |
129 | done | 129 | done |
130 | } | 130 | } |
131 | 131 | ||
132 | antigen-revert () { | 132 | antigen-revert () { |
133 | if [[ -f $ADOTDIR/revert-info ]]; then | 133 | if [[ -f $ADOTDIR/revert-info ]]; then |
134 | cat $ADOTDIR/revert-info | sed '1!p' | while read line; do | 134 | cat $ADOTDIR/revert-info | sed '1!p' | while read line; do |
135 | dir="$(echo "$line" | cut -d: -f1)" | 135 | dir="$(echo "$line" | cut -d: -f1)" |
136 | git --git-dir="$dir/.git" --work-tree="$dir" \ | 136 | git --git-dir="$dir/.git" --work-tree="$dir" \ |
137 | checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null | 137 | checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null |
138 | 138 | ||
139 | done | 139 | done |
140 | 140 | ||
141 | echo "Reverted to state before running -update on $( | 141 | echo "Reverted to state before running -update on $( |
142 | cat $ADOTDIR/revert-info | sed -n 1p)." | 142 | cat $ADOTDIR/revert-info | sed -n 1p)." |
143 | 143 | ||
144 | else | 144 | else |
145 | echo 'No revert information available. Cannot revert.' >&2 | 145 | echo 'No revert information available. Cannot revert.' >&2 |
146 | fi | 146 | fi |
147 | 147 | ||
148 | 148 | ||
149 | } | 149 | } |
150 | 150 | ||
151 | -antigen-get-clone-dir () { | 151 | -antigen-get-clone-dir () { |
152 | # Takes a repo url and gives out the path that this url needs to be cloned | 152 | # Takes a repo url and gives out the path that this url needs to be cloned |
153 | # to. Doesn't actually clone anything. | 153 | # to. Doesn't actually clone anything. |
154 | echo -n $ADOTDIR/repos/ | 154 | echo -n $ADOTDIR/repos/ |
155 | 155 | ||
156 | if [[ "$1" == "https://github.com/sorin-ionescu/prezto.git" ]]; then | 156 | if [[ "$1" == "https://github.com/sorin-ionescu/prezto.git" ]]; then |
157 | # Prezto's directory *has* to be `.zprezto`. | 157 | # Prezto's directory *has* to be `.zprezto`. |
158 | echo .zprezto | 158 | echo .zprezto |
159 | 159 | ||
160 | else | 160 | else |
161 | echo "$1" | sed \ | 161 | echo "$1" | sed \ |
162 | -e 's./.-SLASH-.g' \ | 162 | -e 's./.-SLASH-.g' \ |
163 | -e 's.:.-COLON-.g' \ | 163 | -e 's.:.-COLON-.g' \ |
164 | -e 's.|.-PIPE-.g' | 164 | -e 's.|.-PIPE-.g' |
165 | 165 | ||
166 | fi | 166 | fi |
167 | } | 167 | } |
168 | 168 | ||
169 | -antigen-get-clone-url () { | 169 | -antigen-get-clone-url () { |
170 | # Takes a repo's clone dir and gives out the repo's original url that was | 170 | # Takes a repo's clone dir and gives out the repo's original url that was |
171 | # used to create the given directory path. | 171 | # used to create the given directory path. |
172 | 172 | ||
173 | if [[ "$1" == ".zprezto" ]]; then | 173 | if [[ "$1" == ".zprezto" ]]; then |
174 | # Prezto's (in `.zprezto`), is assumed to be from `sorin-ionescu`'s | 174 | # Prezto's (in `.zprezto`), is assumed to be from `sorin-ionescu`'s |
175 | # remote. | 175 | # remote. |
176 | echo https://github.com/sorin-ionescu/prezto.git | 176 | echo https://github.com/sorin-ionescu/prezto.git |
177 | 177 | ||
178 | else | 178 | else |
179 | echo "$1" | sed \ | 179 | echo "$1" | sed \ |
180 | -e "s:^$ADOTDIR/repos/::" \ | 180 | -e "s:^$ADOTDIR/repos/::" \ |
181 | -e 's.-SLASH-./.g' \ | 181 | -e 's.-SLASH-./.g' \ |
182 | -e 's.-COLON-.:.g' \ | 182 | -e 's.-COLON-.:.g' \ |
183 | -e 's.-PIPE-.|.g' | 183 | -e 's.-PIPE-.|.g' |
184 | 184 | ||
185 | fi | 185 | fi |
186 | } | 186 | } |
187 | 187 | ||
188 | -antigen-ensure-repo () { | 188 | -antigen-ensure-repo () { |
189 | 189 | ||
190 | # Ensure that a clone exists for the given repo url and branch. If the first | 190 | # Ensure that a clone exists for the given repo url and branch. If the first |
191 | # argument is `--update` and if a clone already exists for the given repo | 191 | # argument is `--update` and if a clone already exists for the given repo |
192 | # and branch, it is pull-ed, i.e., updated. | 192 | # and branch, it is pull-ed, i.e., updated. |
193 | 193 | ||
194 | # Argument defaults. | 194 | # Argument defaults. |
195 | # The url. No sane default for this, so just empty. | 195 | # The url. No sane default for this, so just empty. |
196 | local url= | 196 | local url= |
197 | # Check if we have to update. | 197 | # Check if we have to update. |
198 | local update=false | 198 | local update=false |
199 | # Verbose output. | 199 | # Verbose output. |
200 | local verbose=false | 200 | local verbose=false |
201 | 201 | ||
202 | eval "$(-antigen-parse-args 'url ; update?, verbose?' "$@")" | 202 | eval "$(-antigen-parse-args 'url ; update?, verbose?' "$@")" |
203 | shift $# | 203 | shift $# |
204 | 204 | ||
205 | # Get the clone's directory as per the given repo url and branch. | 205 | # Get the clone's directory as per the given repo url and branch. |
206 | local clone_dir="$(-antigen-get-clone-dir $url)" | 206 | local clone_dir="$(-antigen-get-clone-dir $url)" |
207 | 207 | ||
208 | # A temporary function wrapping the `git` command with repeated arguments. | 208 | # A temporary function wrapping the `git` command with repeated arguments. |
209 | --plugin-git () { | 209 | --plugin-git () { |
210 | (cd "$clone_dir" && git --no-pager "$@") | 210 | (cd "$clone_dir" && git --no-pager "$@") |
211 | } | 211 | } |
212 | 212 | ||
213 | # Clone if it doesn't already exist. | 213 | # Clone if it doesn't already exist. |
214 | if [[ ! -d $clone_dir ]]; then | 214 | if [[ ! -d $clone_dir ]]; then |
215 | git clone --recursive "${url%|*}" "$clone_dir" | 215 | git clone --recursive "${url%|*}" "$clone_dir" |
216 | elif $update; then | 216 | elif $update; then |
217 | # Save current revision. | 217 | # Save current revision. |
218 | local old_rev="$(--plugin-git rev-parse HEAD)" | 218 | local old_rev="$(--plugin-git rev-parse HEAD)" |
219 | # Pull changes if update requested. | 219 | # Pull changes if update requested. |
220 | --plugin-git pull | 220 | --plugin-git pull |
221 | # Update submodules. | 221 | # Update submodules. |
222 | --plugin-git submodule update --recursive | 222 | --plugin-git submodule update --recursive |
223 | # Get the new revision. | 223 | # Get the new revision. |
224 | local new_rev="$(--plugin-git rev-parse HEAD)" | 224 | local new_rev="$(--plugin-git rev-parse HEAD)" |
225 | fi | 225 | fi |
226 | 226 | ||
227 | # If its a specific branch that we want, checkout that branch. | 227 | # If its a specific branch that we want, checkout that branch. |
228 | if [[ $url == *\|* ]]; then | 228 | if [[ $url == *\|* ]]; then |
229 | local current_branch=${$(--plugin-git symbolic-ref HEAD)##refs/heads/} | 229 | local current_branch=${$(--plugin-git symbolic-ref HEAD)##refs/heads/} |
230 | local requested_branch="${url#*|}" | 230 | local requested_branch="${url#*|}" |
231 | # Only do the checkout when we are not already on the branch. | 231 | # Only do the checkout when we are not already on the branch. |
232 | [[ $requested_branch != $current_branch ]] && | 232 | [[ $requested_branch != $current_branch ]] && |
233 | --plugin-git checkout $requested_branch | 233 | --plugin-git checkout $requested_branch |
234 | fi | 234 | fi |
235 | 235 | ||
236 | if [[ -n $old_rev && $old_rev != $new_rev ]]; then | 236 | if [[ -n $old_rev && $old_rev != $new_rev ]]; then |
237 | echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. | 237 | echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. |
238 | if $verbose; then | 238 | if $verbose; then |
239 | --plugin-git log --oneline --reverse --no-merges --stat '@{1}..' | 239 | --plugin-git log --oneline --reverse --no-merges --stat '@{1}..' |
240 | fi | 240 | fi |
241 | fi | 241 | fi |
242 | 242 | ||
243 | # Remove the temporary git wrapper function. | 243 | # Remove the temporary git wrapper function. |
244 | unfunction -- --plugin-git | 244 | unfunction -- --plugin-git |
245 | 245 | ||
246 | } | 246 | } |
247 | 247 | ||
248 | -antigen-load () { | 248 | -antigen-load () { |
249 | 249 | ||
250 | local url="$1" | 250 | local url="$1" |
251 | local loc="$2" | 251 | local loc="$2" |
252 | local btype="$3" | 252 | local btype="$3" |
253 | local make_local_clone="$4" | 253 | local make_local_clone="$4" |
254 | 254 | ||
255 | # The full location where the plugin is located. | 255 | # The full location where the plugin is located. |
256 | local location | 256 | local location |
257 | if $make_local_clone; then | 257 | if $make_local_clone; then |
258 | location="$(-antigen-get-clone-dir "$url")/$loc" | 258 | location="$(-antigen-get-clone-dir "$url")/$loc" |
259 | else | 259 | else |
260 | location="$url" | 260 | location="$url" |
261 | fi | 261 | fi |
262 | 262 | ||
263 | if [[ $btype == theme ]]; then | 263 | if [[ $btype == theme ]]; then |
264 | 264 | ||
265 | # Of course, if its a theme, the location would point to the script | 265 | # Of course, if its a theme, the location would point to the script |
266 | # file. | 266 | # file. |
267 | source "$location" | 267 | source "$location" |
268 | 268 | ||
269 | else | 269 | else |
270 | 270 | ||
271 | # Source the plugin script. | 271 | # Source the plugin script. |
272 | # FIXME: I don't know. Looks very very ugly. Needs a better | 272 | # FIXME: I don't know. Looks very very ugly. Needs a better |
273 | # implementation once tests are ready. | 273 | # implementation once tests are ready. |
274 | local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" | 274 | local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" |
275 | 275 | ||
276 | if [[ -f $location/$script_loc ]]; then | 276 | if [[ -f $location/$script_loc ]]; then |
277 | # If we have a `*.plugin.zsh`, source it. | 277 | # If we have a `*.plugin.zsh`, source it. |
278 | source "$location/$script_loc" | 278 | source "$location/$script_loc" |
279 | 279 | ||
280 | elif [[ -f $location/init.zsh ]]; then | 280 | elif [[ -f $location/init.zsh ]]; then |
281 | # If we have a `init.zsh` | 281 | # If we have a `init.zsh` |
282 | if (( $+functions[pmodload] )); then | 282 | if (( $+functions[pmodload] )); then |
283 | # If pmodload is defined pmodload the module. Remove `modules/` | 283 | # If pmodload is defined pmodload the module. Remove `modules/` |
284 | # from loc to find module name. | 284 | # from loc to find module name. |
285 | pmodload "${loc#modules/}" | 285 | pmodload "${loc#modules/}" |
286 | else | 286 | else |
287 | # Otherwise source it. | 287 | # Otherwise source it. |
288 | source "$location/init.zsh" | 288 | source "$location/init.zsh" |
289 | fi | 289 | fi |
290 | 290 | ||
291 | elif ls "$location" | grep -qm1 '\.zsh$'; then | 291 | elif ls "$location" | grep -qm1 '\.zsh$'; then |
292 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` | 292 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` |
293 | # files. | 293 | # files. |
294 | for script ($location/*.zsh(N)) source "$script" | 294 | for script ($location/*.zsh(N)) source "$script" |
295 | 295 | ||
296 | elif ls "$location" | grep -qm1 '\.sh$'; then | 296 | elif ls "$location" | grep -qm1 '\.sh$'; then |
297 | # If there are no `*.zsh` files either, we look for and source any | 297 | # If there are no `*.zsh` files either, we look for and source any |
298 | # `*.sh` files instead. | 298 | # `*.sh` files instead. |
299 | for script ($location/*.sh(N)) source "$script" | 299 | for script ($location/*.sh(N)) source "$script" |
300 | 300 | ||
301 | fi | 301 | fi |
302 | 302 | ||
303 | # Add to $fpath, for completion(s). | 303 | # Add to $fpath, for completion(s). |
304 | fpath=($location $fpath) | 304 | fpath=($location $fpath) |
305 | 305 | ||
306 | fi | 306 | fi |
307 | 307 | ||
308 | } | 308 | } |
309 | 309 | ||
310 | # Update (with `git pull`) antigen itself. | 310 | # Update (with `git pull`) antigen itself. |
311 | # TODO: Once update is finished, show a summary of the new commits, as a kind of | 311 | # TODO: Once update is finished, show a summary of the new commits, as a kind of |
312 | # "what's new" message. | 312 | # "what's new" message. |
313 | antigen-selfupdate () { | 313 | antigen-selfupdate () { |
314 | ( cd $_ANTIGEN_INSTALL_DIR | 314 | ( cd $_ANTIGEN_INSTALL_DIR |
315 | if [[ ! -d .git ]]; then | 315 | if [[ ! -d .git ]]; then |
316 | echo "Your copy of antigen doesn't appear to be a git clone. " \ | 316 | echo "Your copy of antigen doesn't appear to be a git clone. " \ |
317 | "The 'selfupdate' command cannot work in this case." | 317 | "The 'selfupdate' command cannot work in this case." |
318 | return 1 | 318 | return 1 |
319 | fi | 319 | fi |
320 | git pull | 320 | git pull |
321 | ) | 321 | ) |
322 | } | 322 | } |
323 | 323 | ||
324 | antigen-cleanup () { | 324 | antigen-cleanup () { |
325 | 325 | ||
326 | # Cleanup unused repositories. | 326 | # Cleanup unused repositories. |
327 | 327 | ||
328 | local force=false | 328 | local force=false |
329 | if [[ $1 == --force ]]; then | 329 | if [[ $1 == --force ]]; then |
330 | force=true | 330 | force=true |
331 | fi | 331 | fi |
332 | 332 | ||
333 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then | 333 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then |
334 | echo "You don't have any bundles." | 334 | echo "You don't have any bundles." |
335 | return 0 | 335 | return 0 |
336 | fi | 336 | fi |
337 | 337 | ||
338 | # Find directores in ADOTDIR/repos, that are not in the bundles record. | 338 | # Find directores in ADOTDIR/repos, that are not in the bundles record. |
339 | local unused_clones="$(comm -13 \ | 339 | local unused_clones="$(comm -13 \ |
340 | <(-antigen-echo-record | | 340 | <(-antigen-echo-record | |
341 | awk '$4 == "true" {print $1}' | | 341 | awk '$4 == "true" {print $1}' | |
342 | while read line; do | 342 | while read line; do |
343 | -antigen-get-clone-dir "$line" | 343 | -antigen-get-clone-dir "$line" |
344 | done | | 344 | done | |
345 | sort -u) \ | 345 | sort -u) \ |
346 | <(ls -d "$ADOTDIR/repos/"* | sort -u))" | 346 | <(ls -d "$ADOTDIR/repos/"* | sort -u))" |
347 | 347 | ||
348 | if [[ -z $unused_clones ]]; then | 348 | if [[ -z $unused_clones ]]; then |
349 | echo "You don't have any unidentified bundles." | 349 | echo "You don't have any unidentified bundles." |
350 | return 0 | 350 | return 0 |
351 | fi | 351 | fi |
352 | 352 | ||
353 | echo 'You have clones for the following repos, but are not used.' | 353 | echo 'You have clones for the following repos, but are not used.' |
354 | echo "$unused_clones" | | 354 | echo "$unused_clones" | |
355 | while read line; do | 355 | while read line; do |
356 | -antigen-get-clone-url "$line" | 356 | -antigen-get-clone-url "$line" |
357 | done | | 357 | done | |
358 | sed -e 's/^/ /' -e 's/|/, branch /' | 358 | sed -e 's/^/ /' -e 's/|/, branch /' |
359 | 359 | ||
360 | if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then | 360 | if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then |
361 | echo | 361 | echo |
362 | echo | 362 | echo |
363 | echo "$unused_clones" | while read line; do | 363 | echo "$unused_clones" | while read line; do |
364 | echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." | 364 | echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." |
365 | rm -rf "$line" | 365 | rm -rf "$line" |
366 | echo ' done.' | 366 | echo ' done.' |
367 | done | 367 | done |
368 | else | 368 | else |
369 | echo | 369 | echo |
370 | echo Nothing deleted. | 370 | echo Nothing deleted. |
371 | fi | 371 | fi |
372 | } | 372 | } |
373 | 373 | ||
374 | antigen-lib () { | 374 | antigen-lib () { |
375 | if [[ -z "$ZSH" ]]; then | 375 | if [[ -z "$ZSH" ]]; then |
376 | export ZSH="$(-antigen-get-clone-dir "$ANTIGEN_DEFAULT_REPO_URL")" | 376 | export ZSH="$(-antigen-get-clone-dir "$ANTIGEN_DEFAULT_REPO_URL")" |
377 | fi | 377 | fi |
378 | antigen-bundle --loc=lib | 378 | antigen-bundle --loc=lib |
379 | } | 379 | } |
380 | 380 | ||
381 | antigen-prezto-lib () { | 381 | antigen-prezto-lib () { |
382 | antigen-bundle sorin-ionescu/prezto | 382 | antigen-bundle sorin-ionescu/prezto |
383 | export ZDOTDIR=$ADOTDIR/repos/ | 383 | export ZDOTDIR=$ADOTDIR/repos/ |
384 | } | 384 | } |
385 | 385 | ||
386 | antigen-theme () { | 386 | antigen-theme () { |
387 | 387 | ||
388 | if [[ "$1" != */* && "$1" != --* ]]; then | 388 | if [[ "$1" != */* && "$1" != --* ]]; then |
389 | # The first argument is just a name of the plugin, to be picked up from | 389 | # The first argument is just a name of the plugin, to be picked up from |
390 | # the default repo. | 390 | # the default repo. |
391 | local name="${1:-robbyrussell}" | 391 | local name="${1:-robbyrussell}" |
392 | antigen-bundle --loc=themes/$name --btype=theme | 392 | antigen-bundle --loc=themes/$name --btype=theme |
393 | 393 | ||
394 | else | 394 | else |
395 | antigen-bundle "$@" --btype=theme | 395 | antigen-bundle "$@" --btype=theme |
396 | 396 | ||
397 | fi | 397 | fi |
398 | 398 | ||
399 | } | 399 | } |
400 | 400 | ||
401 | antigen-apply () { | 401 | antigen-apply () { |
402 | |||
402 | # Initialize completion. | 403 | # Initialize completion. |
403 | local cd | 404 | local cdef |
404 | for cd in $__deferred_compdefs; do | 405 | |
405 | compdef $cd | 406 | # Load the compinit module. This will readefine the `compdef` function to |
406 | done | 407 | # the one that actually initializes completions. |
408 | autoload -U compinit | ||
409 | compinit -i | ||
410 | |||
411 | # Apply all `compinit`s that have been deferred. | ||
412 | eval "$(for cdef in $__deferred_compdefs; do | ||
413 | echo compdef $cdef | ||
414 | done)" | ||
415 | |||
407 | unset __deferred_compdefs | 416 | unset __deferred_compdefs |
408 | compdef _antigen antigen | 417 | |
409 | } | 418 | } |
410 | 419 | ||
411 | antigen-list () { | 420 | antigen-list () { |
412 | # List all currently installed bundles. | 421 | # List all currently installed bundles. |
413 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then | 422 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then |
414 | echo "You don't have any bundles." >&2 | 423 | echo "You don't have any bundles." >&2 |
415 | return 1 | 424 | return 1 |
416 | else | 425 | else |
417 | -antigen-echo-record | sort -u | 426 | -antigen-echo-record | sort -u |
418 | fi | 427 | fi |
419 | } | 428 | } |
420 | 429 | ||
421 | antigen-snapshot () { | 430 | antigen-snapshot () { |
422 | 431 | ||
423 | local snapshot_file="${1:-antigen-shapshot}" | 432 | local snapshot_file="${1:-antigen-shapshot}" |
424 | 433 | ||
425 | # The snapshot content lines are pairs of repo-url and git version hash, in | 434 | # The snapshot content lines are pairs of repo-url and git version hash, in |
426 | # the form: | 435 | # the form: |
427 | # <version-hash> <repo-url> | 436 | # <version-hash> <repo-url> |
428 | local snapshot_content="$(-antigen-echo-record | | 437 | local snapshot_content="$(-antigen-echo-record | |
429 | grep 'true$' | | 438 | grep 'true$' | |
430 | sed 's/ .*$//' | | 439 | sed 's/ .*$//' | |
431 | sort -u | | 440 | sort -u | |
432 | while read url; do | 441 | while read url; do |
433 | local dir="$(-antigen-get-clone-dir "$url")" | 442 | local dir="$(-antigen-get-clone-dir "$url")" |
434 | local version_hash="$(cd "$dir" && git rev-parse HEAD)" | 443 | local version_hash="$(cd "$dir" && git rev-parse HEAD)" |
435 | echo "$version_hash $url" | 444 | echo "$version_hash $url" |
436 | done)" | 445 | done)" |
437 | 446 | ||
438 | { | 447 | { |
439 | # The first line in the snapshot file is for metadata, in the form: | 448 | # The first line in the snapshot file is for metadata, in the form: |
440 | # key='value'; key='value'; key='value'; | 449 | # key='value'; key='value'; key='value'; |
441 | # Where `key`s are valid shell variable names. | 450 | # Where `key`s are valid shell variable names. |
442 | 451 | ||
443 | # Snapshot version. Has no relation to antigen version. If the snapshot | 452 | # Snapshot version. Has no relation to antigen version. If the snapshot |
444 | # file format changes, this number can be incremented. | 453 | # file format changes, this number can be incremented. |
445 | echo -n "version='1';" | 454 | echo -n "version='1';" |
446 | 455 | ||
447 | # Snapshot creation date+time. | 456 | # Snapshot creation date+time. |
448 | echo -n " created_on='$(date)';" | 457 | echo -n " created_on='$(date)';" |
449 | 458 | ||
450 | # Add a checksum with the md5 checksum of all the snapshot lines. | 459 | # Add a checksum with the md5 checksum of all the snapshot lines. |
451 | local checksum="$(echo "$snapshot_content" | md5sum)" | 460 | local checksum="$(echo "$snapshot_content" | md5sum)" |
452 | echo -n " checksum='${checksum%% *}';" | 461 | echo -n " checksum='${checksum%% *}';" |
453 | 462 | ||
454 | # A newline after the metadata and then the snapshot lines. | 463 | # A newline after the metadata and then the snapshot lines. |
455 | echo "\n$snapshot_content" | 464 | echo "\n$snapshot_content" |
456 | 465 | ||
457 | } > "$snapshot_file" | 466 | } > "$snapshot_file" |
458 | 467 | ||
459 | } | 468 | } |
460 | 469 | ||
461 | antigen-restore () { | 470 | antigen-restore () { |
462 | 471 | ||
463 | if [[ $# == 0 ]]; then | 472 | if [[ $# == 0 ]]; then |
464 | echo 'Please provide a snapshot file to restore from.' >&2 | 473 | echo 'Please provide a snapshot file to restore from.' >&2 |
465 | return 1 | 474 | return 1 |
466 | fi | 475 | fi |
467 | 476 | ||
468 | local snapshot_file="$1" | 477 | local snapshot_file="$1" |
469 | 478 | ||
470 | # TODO: Before doing anything with the snapshot file, verify its checksum. | 479 | # TODO: Before doing anything with the snapshot file, verify its checksum. |
471 | # If it fails, notify this to the user and confirm if restore should | 480 | # If it fails, notify this to the user and confirm if restore should |
472 | # proceed. | 481 | # proceed. |
473 | 482 | ||
474 | echo -n "Restoring from $snapshot_file..." | 483 | echo -n "Restoring from $snapshot_file..." |
475 | 484 | ||
476 | sed -n '1!p' "$snapshot_file" | | 485 | sed -n '1!p' "$snapshot_file" | |
477 | while read line; do | 486 | while read line; do |
478 | 487 | ||
479 | local version_hash="${line%% *}" | 488 | local version_hash="${line%% *}" |
480 | local url="${line##* }" | 489 | local url="${line##* }" |
481 | local clone_dir="$(-antigen-get-clone-dir "$url")" | 490 | local clone_dir="$(-antigen-get-clone-dir "$url")" |
482 | 491 | ||
483 | if [[ ! -d $clone_dir ]]; then | 492 | if [[ ! -d $clone_dir ]]; then |
484 | git clone "$url" "$clone_dir" > /dev/null | 493 | git clone "$url" "$clone_dir" > /dev/null |
485 | fi | 494 | fi |
486 | 495 | ||
487 | (cd "$clone_dir" && git checkout $version_hash) 2> /dev/null | 496 | (cd "$clone_dir" && git checkout $version_hash) 2> /dev/null |
488 | 497 | ||
489 | done | 498 | done |
490 | 499 | ||
491 | echo ' done.' | 500 | echo ' done.' |
492 | echo 'Please open a new shell to get the restored changes.' | 501 | echo 'Please open a new shell to get the restored changes.' |
493 | } | 502 | } |
494 | 503 | ||
495 | antigen-help () { | 504 | antigen-help () { |
496 | cat <<EOF | 505 | cat <<EOF |
497 | Antigen is a plugin management system for zsh. It makes it easy to grab awesome | 506 | Antigen is a plugin management system for zsh. It makes it easy to grab awesome |
498 | shell scripts and utilities, put up on github. For further details and complete | 507 | shell scripts and utilities, put up on github. For further details and complete |
499 | documentation, visit the project's page at 'http://antigen.sharats.me'. | 508 | documentation, visit the project's page at 'http://antigen.sharats.me'. |
500 | EOF | 509 | EOF |
501 | } | 510 | } |
502 | 511 | ||
503 | # A syntax sugar to avoid the `-` when calling antigen commands. With this | 512 | # A syntax sugar to avoid the `-` when calling antigen commands. With this |
504 | # function, you can write `antigen-bundle` as `antigen bundle` and so on. | 513 | # function, you can write `antigen-bundle` as `antigen bundle` and so on. |
505 | antigen () { | 514 | antigen () { |
506 | local cmd="$1" | 515 | local cmd="$1" |
507 | shift | 516 | shift |
508 | "antigen-$cmd" "$@" | 517 | "antigen-$cmd" "$@" |
509 | } | 518 | } |
510 | 519 | ||
511 | -antigen-parse-args () { | 520 | -antigen-parse-args () { |
512 | # An argument parsing functionality to parse arguments the *antigen* way :). | 521 | # An argument parsing functionality to parse arguments the *antigen* way :). |
513 | # Takes one first argument (called spec), which dictates how to parse and | 522 | # Takes one first argument (called spec), which dictates how to parse and |
514 | # the rest of the arguments are parsed. Outputs a piece of valid shell code | 523 | # the rest of the arguments are parsed. Outputs a piece of valid shell code |
515 | # that can be passed to `eval` inside a function which creates the arguments | 524 | # that can be passed to `eval` inside a function which creates the arguments |
516 | # and their values as local variables. Suggested use is to set the defaults | 525 | # and their values as local variables. Suggested use is to set the defaults |
517 | # to all arguments first and then eval the output of this function. | 526 | # to all arguments first and then eval the output of this function. |
518 | 527 | ||
519 | # Spec: Only long argument supported. No support for parsing short options. | 528 | # Spec: Only long argument supported. No support for parsing short options. |
520 | # The spec must have two sections, separated by a `;`. | 529 | # The spec must have two sections, separated by a `;`. |
521 | # '<positional-arguments>;<keyword-only-arguments>' | 530 | # '<positional-arguments>;<keyword-only-arguments>' |
522 | # Positional arguments are passed as just values, like `command a b`. | 531 | # Positional arguments are passed as just values, like `command a b`. |
523 | # Keyword arguments are passed as a `--name=value` pair, like `command | 532 | # Keyword arguments are passed as a `--name=value` pair, like `command |
524 | # --arg1=a --arg2=b`. | 533 | # --arg1=a --arg2=b`. |
525 | 534 | ||
526 | # Each argument in the spec is separated by a `,`. Each keyword argument can | 535 | # Each argument in the spec is separated by a `,`. Each keyword argument can |
527 | # end in a `:` to specifiy that this argument wants a value, otherwise it | 536 | # end in a `:` to specifiy that this argument wants a value, otherwise it |
528 | # doesn't take a value. (The value in the output when the keyword argument | 537 | # doesn't take a value. (The value in the output when the keyword argument |
529 | # doesn't have a `:` is `true`). | 538 | # doesn't have a `:` is `true`). |
530 | 539 | ||
531 | # Arguments in either section can end with a `?` (should come after `:`, if | 540 | # Arguments in either section can end with a `?` (should come after `:`, if |
532 | # both are present), means optional. FIXME: Not yet implemented. | 541 | # both are present), means optional. FIXME: Not yet implemented. |
533 | 542 | ||
534 | # See the test file, tests/arg-parser.t for (working) examples. | 543 | # See the test file, tests/arg-parser.t for (working) examples. |
535 | 544 | ||
536 | local spec="$1" | 545 | local spec="$1" |
537 | shift | 546 | shift |
538 | 547 | ||
539 | # Sanitize the spec | 548 | # Sanitize the spec |
540 | spec="$(echo "$spec" | tr '\n' ' ' | sed 's/[[:space:]]//g')" | 549 | spec="$(echo "$spec" | tr '\n' ' ' | sed 's/[[:space:]]//g')" |
541 | 550 | ||
542 | local code='' | 551 | local code='' |
543 | 552 | ||
544 | --add-var () { | 553 | --add-var () { |
545 | test -z "$code" || code="$code\n" | 554 | test -z "$code" || code="$code\n" |
546 | code="${code}local $1='$2'" | 555 | code="${code}local $1='$2'" |
547 | } | 556 | } |
548 | 557 | ||
549 | local positional_args="$(echo "$spec" | cut -d\; -f1)" | 558 | local positional_args="$(echo "$spec" | cut -d\; -f1)" |
550 | local positional_args_count="$(echo $positional_args | | 559 | local positional_args_count="$(echo $positional_args | |
551 | awk -F, '{print NF}')" | 560 | awk -F, '{print NF}')" |
552 | 561 | ||
553 | # Set spec values based on the positional arguments. | 562 | # Set spec values based on the positional arguments. |
554 | local i=1 | 563 | local i=1 |
555 | while [[ -n $1 && $1 != --* ]]; do | 564 | while [[ -n $1 && $1 != --* ]]; do |
556 | 565 | ||
557 | if (( $i > $positional_args_count )); then | 566 | if (( $i > $positional_args_count )); then |
558 | echo "Only $positional_args_count positional arguments allowed." >&2 | 567 | echo "Only $positional_args_count positional arguments allowed." >&2 |
559 | echo "Found at least one more: '$1'" >&2 | 568 | echo "Found at least one more: '$1'" >&2 |
560 | return | 569 | return |
561 | fi | 570 | fi |
562 | 571 | ||
563 | local name_spec="$(echo "$positional_args" | cut -d, -f$i)" | 572 | local name_spec="$(echo "$positional_args" | cut -d, -f$i)" |
564 | local name="${${name_spec%\?}%:}" | 573 | local name="${${name_spec%\?}%:}" |
565 | local value="$1" | 574 | local value="$1" |
566 | 575 | ||
567 | if echo "$code" | grep -qm1 "^local $name="; then | 576 | if echo "$code" | grep -qm1 "^local $name="; then |
568 | echo "Argument '$name' repeated with the value '$value'". >&2 | 577 | echo "Argument '$name' repeated with the value '$value'". >&2 |
569 | return | 578 | return |
570 | fi | 579 | fi |
571 | 580 | ||
572 | --add-var $name "$value" | 581 | --add-var $name "$value" |
573 | 582 | ||
574 | shift | 583 | shift |
575 | i=$(($i + 1)) | 584 | i=$(($i + 1)) |
576 | done | 585 | done |
577 | 586 | ||
578 | local keyword_args="$( | 587 | local keyword_args="$( |
579 | # Positional arguments can double up as keyword arguments too. | 588 | # Positional arguments can double up as keyword arguments too. |
580 | echo "$positional_args" | tr , '\n' | | 589 | echo "$positional_args" | tr , '\n' | |
581 | while read line; do | 590 | while read line; do |
582 | if [[ $line == *\? ]]; then | 591 | if [[ $line == *\? ]]; then |
583 | echo "${line%?}:?" | 592 | echo "${line%?}:?" |
584 | else | 593 | else |
585 | echo "$line:" | 594 | echo "$line:" |
586 | fi | 595 | fi |
587 | done | 596 | done |
588 | 597 | ||
589 | # Specified keyword arguments. | 598 | # Specified keyword arguments. |
590 | echo "$spec" | cut -d\; -f2 | tr , '\n' | 599 | echo "$spec" | cut -d\; -f2 | tr , '\n' |
591 | )" | 600 | )" |
592 | local keyword_args_count="$(echo $keyword_args | awk -F, '{print NF}')" | 601 | local keyword_args_count="$(echo $keyword_args | awk -F, '{print NF}')" |
593 | 602 | ||
594 | # Set spec values from keyword arguments, if any. The remaining arguments | 603 | # Set spec values from keyword arguments, if any. The remaining arguments |
595 | # are all assumed to be keyword arguments. | 604 | # are all assumed to be keyword arguments. |
596 | while [[ $1 == --* ]]; do | 605 | while [[ $1 == --* ]]; do |
597 | # Remove the `--` at the start. | 606 | # Remove the `--` at the start. |
598 | local arg="${1#--}" | 607 | local arg="${1#--}" |
599 | 608 | ||
600 | # Get the argument name and value. | 609 | # Get the argument name and value. |
601 | if [[ $arg != *=* ]]; then | 610 | if [[ $arg != *=* ]]; then |
602 | local name="$arg" | 611 | local name="$arg" |
603 | local value='' | 612 | local value='' |
604 | else | 613 | else |
605 | local name="${arg%\=*}" | 614 | local name="${arg%\=*}" |
606 | local value="${arg#*=}" | 615 | local value="${arg#*=}" |
607 | fi | 616 | fi |
608 | 617 | ||
609 | if echo "$code" | grep -qm1 "^local $name="; then | 618 | if echo "$code" | grep -qm1 "^local $name="; then |
610 | echo "Argument '$name' repeated with the value '$value'". >&2 | 619 | echo "Argument '$name' repeated with the value '$value'". >&2 |
611 | return | 620 | return |
612 | fi | 621 | fi |
613 | 622 | ||
614 | # The specification for this argument, used for validations. | 623 | # The specification for this argument, used for validations. |
615 | local arg_line="$(echo "$keyword_args" | grep -m1 "^$name:\??\?")" | 624 | local arg_line="$(echo "$keyword_args" | grep -m1 "^$name:\??\?")" |
616 | 625 | ||
617 | # Validate argument and value. | 626 | # Validate argument and value. |
618 | if [[ -z $arg_line ]]; then | 627 | if [[ -z $arg_line ]]; then |
619 | # This argument is not known to us. | 628 | # This argument is not known to us. |
620 | echo "Unknown argument '$name'." >&2 | 629 | echo "Unknown argument '$name'." >&2 |
621 | return | 630 | return |
622 | 631 | ||
623 | elif (echo "$arg_line" | grep -qm1 ':') && [[ -z $value ]]; then | 632 | elif (echo "$arg_line" | grep -qm1 ':') && [[ -z $value ]]; then |
624 | # This argument needs a value, but is not provided. | 633 | # This argument needs a value, but is not provided. |
625 | echo "Required argument for '$name' not provided." >&2 | 634 | echo "Required argument for '$name' not provided." >&2 |
626 | return | 635 | return |
627 | 636 | ||
628 | elif (echo "$arg_line" | grep -vqm1 ':') && [[ ! -z $value ]]; then | 637 | elif (echo "$arg_line" | grep -vqm1 ':') && [[ ! -z $value ]]; then |
629 | # This argument doesn't need a value, but is provided. | 638 | # This argument doesn't need a value, but is provided. |
630 | echo "No argument required for '$name', but provided '$value'." >&2 | 639 | echo "No argument required for '$name', but provided '$value'." >&2 |
631 | return | 640 | return |
632 | 641 | ||
633 | fi | 642 | fi |
634 | 643 | ||
635 | if [[ -z $value ]]; then | 644 | if [[ -z $value ]]; then |
636 | value=true | 645 | value=true |
637 | fi | 646 | fi |
638 | 647 | ||
639 | --add-var "${name//-/_}" "$value" | 648 | --add-var "${name//-/_}" "$value" |
640 | shift | 649 | shift |
641 | done | 650 | done |
642 | 651 | ||
643 | echo "$code" | 652 | echo "$code" |
644 | 653 | ||
645 | unfunction -- --add-var | 654 | unfunction -- --add-var |
646 | 655 | ||
647 | } | 656 | } |
648 | 657 | ||
649 | # Echo the bundle specs as in the record. The first line is not echoed since it | 658 | # Echo the bundle specs as in the record. The first line is not echoed since it |
650 | # is a blank line. | 659 | # is a blank line. |
651 | -antigen-echo-record () { | 660 | -antigen-echo-record () { |
652 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' | 661 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' |
653 | } | 662 | } |
654 | 663 | ||
655 | -antigen-env-setup () { | 664 | -antigen-env-setup () { |
656 | 665 | ||
657 | # Helper function: Same as `export $1=$2`, but will only happen if the name | 666 | # Helper function: Same as `export $1=$2`, but will only happen if the name |
658 | # specified by `$1` is not already set. | 667 | # specified by `$1` is not already set. |
659 | -set-default () { | 668 | -set-default () { |
660 | local arg_name="$1" | 669 | local arg_name="$1" |
661 | local arg_value="$2" | 670 | local arg_value="$2" |
662 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 671 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
663 | } | 672 | } |
664 | 673 | ||
665 | # Pre-startup initializations. | 674 | # Pre-startup initializations. |
666 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 675 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
667 | https://github.com/robbyrussell/oh-my-zsh.git | 676 | https://github.com/robbyrussell/oh-my-zsh.git |
668 | -set-default ADOTDIR $HOME/.antigen | 677 | -set-default ADOTDIR $HOME/.antigen |
669 | 678 | ||
670 | # Load the compinit module. Required for `compdef` to be defined, which is | ||
671 | # used by many plugins to define completions. | ||
672 | autoload -U compinit | ||
673 | compinit -i | ||
674 | |||
675 | # Setup antigen's own completion. | 679 | # Setup antigen's own completion. |
676 | compdef _antigen antigen | 680 | compdef _antigen antigen |
677 | 681 | ||
678 | # Remove private functions. | 682 | # Remove private functions. |
679 | unfunction -- -set-default | 683 | unfunction -- -set-default |
680 | } | 684 | } |
681 | 685 | ||
682 | # Setup antigen's autocompletion | 686 | # Setup antigen's autocompletion |
683 | _antigen () { | 687 | _antigen () { |
684 | compadd \ | 688 | compadd \ |
685 | bundle \ | 689 | bundle \ |
686 | bundles \ | 690 | bundles \ |
687 | update \ | 691 | update \ |
688 | revert \ | 692 | revert \ |
689 | list \ | 693 | list \ |
690 | cleanup \ | 694 | cleanup \ |
691 | lib \ | 695 | lib \ |
692 | selfupdate \ | 696 | selfupdate \ |
693 | theme \ | 697 | theme \ |
694 | apply \ | 698 | apply \ |