Commit c3198e0aa07428afb76c5503ac8e6118ad233149

Authored by Shrikant Sharat
1 parent e0d9cfa43f

Set `$ZSH` to oh-my-zsh clone location in `-lib`. Fix #46.

Some plugins seem to rely on the `$ZSH` variable pointing to the oh-my-zsh clone
being used. See README for more.

Showing 2 changed files with 9 additions and 3 deletions Inline Diff

1 # Antigen <sup>&beta;</sup> 1 # Antigen <sup>&beta;</sup>
2 2
3 [![Build Status](https://secure.travis-ci.org/zsh-users/antigen.png)](http://travis-ci.org/zsh-users/antigen) 3 [![Build Status](https://secure.travis-ci.org/zsh-users/antigen.png)](http://travis-ci.org/zsh-users/antigen)
4 4
5 Antigen is a small set of functions that help you easily manage your shell (zsh) 5 Antigen is a small set of functions that help you easily manage your shell (zsh)
6 plugins, called bundles. The concept is pretty much the same as bundles in a 6 plugins, called bundles. The concept is pretty much the same as bundles in a
7 typical vim+pathogen setup. Antigen is to zsh, what [Vundle][] is to vim. 7 typical vim+pathogen setup. Antigen is to zsh, what [Vundle][] is to vim.
8 8
9 Please note that this is a very new project and can be considered beta at best. 9 Please note that this is a very new project and can be considered beta at best.
10 That said, I am using antigen full time now on my work machine. 10 That said, I am using antigen full time now on my work machine.
11 11
12 Note: Please read the commit comments of the changesets when you pull a new 12 Note: Please read the commit comments of the changesets when you pull a new
13 version of antigen. 13 version of antigen.
14 14
15 ## Show off 15 ## Show off
16 16
17 > Enough talk. Let's fight! 17 > Enough talk. Let's fight!
18 > -- Po, Kung-fu Panda. 18 > -- Po, Kung-fu Panda.
19 19
20 You're going to experience antigen right in your open shell. No `.zshrc` 20 You're going to experience antigen right in your open shell. No `.zshrc`
21 tweaking and reading the rest of this documentation. Kinda like an ice-cream 21 tweaking and reading the rest of this documentation. Kinda like an ice-cream
22 sample, if you will. 22 sample, if you will.
23 23
24 Get and load antigen. 24 Get and load antigen.
25 25
26 curl https://raw.github.com/zsh-users/antigen/master/antigen.zsh > antigen.zsh 26 curl https://raw.github.com/zsh-users/antigen/master/antigen.zsh > antigen.zsh
27 source antigen.zsh 27 source antigen.zsh
28 28
29 There. You now have all the antigen goodies. Let's try install some plugins. How 29 There. You now have all the antigen goodies. Let's try install some plugins. How
30 about some color to start with. Get the [syntax highlighting plugin][] by 30 about some color to start with. Get the [syntax highlighting plugin][] by
31 running 31 running
32 32
33 antigen-bundle zsh-users/zsh-syntax-highlighting 33 antigen-bundle zsh-users/zsh-syntax-highlighting
34 34
35 Now let it do its thing and once you're back at your prompt, try and type a 35 Now let it do its thing and once you're back at your prompt, try and type a
36 command. See that? Colors! 36 command. See that? Colors!
37 37
38 So, you do git? ruby? git and ruby? There are lots of awesome plugins over at 38 So, you do git? ruby? git and ruby? There are lots of awesome plugins over at
39 oh-my-zsh. Treat yourself to some. 39 oh-my-zsh. Treat yourself to some.
40 40
41 antigen-bundle robbyrussell/oh-my-zsh plugins/ruby 41 antigen-bundle robbyrussell/oh-my-zsh plugins/ruby
42 # Or for the lazy, 42 # Or for the lazy,
43 antigen-bundle git 43 antigen-bundle git
44 44
45 There are lots of plugins out there in the wild and people are writing zsh 45 There are lots of plugins out there in the wild and people are writing zsh
46 utilities as small scripts all the time. Antigen is compatible with all of them. 46 utilities as small scripts all the time. Antigen is compatible with all of them.
47 The plugins and scripts don't need any special handling to be compatible with 47 The plugins and scripts don't need any special handling to be compatible with
48 antigen. 48 antigen.
49 49
50 Another example, [kennethreitz's autoenv][autoenv]. Just a bundle command away. 50 Another example, [kennethreitz's autoenv][autoenv]. Just a bundle command away.
51 51
52 antigen-bundle kennethreitz/autoenv 52 antigen-bundle kennethreitz/autoenv
53 53
54 And boom! you have all the autoenv goodness. Just remember how you used to do 54 And boom! you have all the autoenv goodness. Just remember how you used to do
55 these before antigen, clone it, modify your bashrc to source it, load a new 55 these before antigen, clone it, modify your bashrc to source it, load a new
56 terminal, all just to test it out. Duh! 56 terminal, all just to test it out. Duh!
57 57
58 A subtle aspect of this is that you can tell antigen to grab just about anything 58 A subtle aspect of this is that you can tell antigen to grab just about anything
59 from anyone's `dotfiles` repo, as long as it is in a directory under any repo on 59 from anyone's `dotfiles` repo, as long as it is in a directory under any repo on
60 github. 60 github.
61 61
62 And themes? How would you like a fancy new prompt for yourself? 62 And themes? How would you like a fancy new prompt for yourself?
63 63
64 antigen-theme funky 64 antigen-theme funky
65 65
66 No? Not your taste? There are many themes available to you, check out the 66 No? Not your taste? There are many themes available to you, check out the
67 oh-my-zsh's [page on themes][]. 67 oh-my-zsh's [page on themes][].
68 68
69 You can install themes from unofficial repos too! 69 You can install themes from unofficial repos too!
70 70
71 antigen-theme XsErG/zsh-themes themes/lazyuser 71 antigen-theme XsErG/zsh-themes themes/lazyuser
72 72
73 See? It's easy! To see how that works, refer to the section on the 73 See? It's easy! To see how that works, refer to the section on the
74 `antigen-theme` command further down. 74 `antigen-theme` command further down.
75 75
76 Note: Many of those plugins and especially themes, assume you have the core 76 Note: Many of those plugins and especially themes, assume you have the core
77 library of oh-my-zsh loaded. So, if you want to experiment further, issue a 77 library of oh-my-zsh loaded. So, if you want to experiment further, issue a
78 78
79 antigen-lib 79 antigen-lib
80 80
81 and continue until you're tired. At which point you can come back to this page 81 and continue until you're tired. At which point you can come back to this page
82 ;) 82 ;)
83 83
84 ## Usage 84 ## Usage
85 85
86 So, now that you're here, I suppose you are convinced and want antigen running 86 So, now that you're here, I suppose you are convinced and want antigen running
87 your shell all the time. Sweet. Let's do it. 87 your shell all the time. Sweet. Let's do it.
88 88
89 First, clone this repo, probably as a submodule if you have your dotfiles in a 89 First, clone this repo, probably as a submodule if you have your dotfiles in a
90 git repo, 90 git repo,
91 91
92 git clone https://github.com/zsh-users/antigen.git 92 git clone https://github.com/zsh-users/antigen.git
93 93
94 The usage should be very familiar to you if you use Vundle. A typical `.zshrc` 94 The usage should be very familiar to you if you use Vundle. A typical `.zshrc`
95 might look like this 95 might look like this
96 96
97 source /path-to-antigen-clone/antigen.zsh 97 source /path-to-antigen-clone/antigen.zsh
98 98
99 # Load the oh-my-zsh's library. 99 # Load the oh-my-zsh's library.
100 antigen-lib 100 antigen-lib
101 101
102 # Bundles from the default repo (robbyrussell's oh-my-zsh). 102 # Bundles from the default repo (robbyrussell's oh-my-zsh).
103 antigen-bundle git 103 antigen-bundle git
104 antigen-bundle heroku 104 antigen-bundle heroku
105 antigen-bundle pip 105 antigen-bundle pip
106 antigen-bundle lein 106 antigen-bundle lein
107 antigen-bundle command-not-found 107 antigen-bundle command-not-found
108 108
109 # Syntax highlighting bundle. 109 # Syntax highlighting bundle.
110 antigen-bundle zsh-users/zsh-syntax-highlighting 110 antigen-bundle zsh-users/zsh-syntax-highlighting
111 111
112 # Load the theme. 112 # Load the theme.
113 antigen-theme robbyrussell 113 antigen-theme robbyrussell
114 114
115 # Tell antigen that you're done. 115 # Tell antigen that you're done.
116 antigen-apply 116 antigen-apply
117 117
118 Open your zsh with this zshrc and you should see all the bundles you defined 118 Open your zsh with this zshrc and you should see all the bundles you defined
119 here, getting installed. Once its done, you are ready to roll. The complete 119 here, getting installed. Once its done, you are ready to roll. The complete
120 syntax for the `antigen-bundle` command is discussed further down on this page. 120 syntax for the `antigen-bundle` command is discussed further down on this page.
121 121
122 ## Motivation 122 ## Motivation
123 123
124 If you use zsh and [oh-my-zsh][], you know that having many different plugins 124 If you use zsh and [oh-my-zsh][], you know that having many different plugins
125 that are developed by many different authors in a single (sub)repo is not very 125 that are developed by many different authors in a single (sub)repo is not very
126 easy to maintain. There are some really fantastic plugins and utilities in 126 easy to maintain. There are some really fantastic plugins and utilities in
127 oh-my-zsh, but having them all in a single repo doesn't really scale well. And I 127 oh-my-zsh, but having them all in a single repo doesn't really scale well. And I
128 admire robbyrussell's efforts for reviewing and merging the gigantic number of 128 admire robbyrussell's efforts for reviewing and merging the gigantic number of
129 pull requests the project gets. We need a better way of plugin management. 129 pull requests the project gets. We need a better way of plugin management.
130 130
131 This was discussed on [a][1] [few][2] [issues][3], but it doesn't look like 131 This was discussed on [a][1] [few][2] [issues][3], but it doesn't look like
132 there was any progress made. So, I'm trying to start this off with antigen, 132 there was any progress made. So, I'm trying to start this off with antigen,
133 hoping to better this situation. Please note that I'm by no means a zsh or any 133 hoping to better this situation. Please note that I'm by no means a zsh or any
134 shell script expert (far from it). 134 shell script expert (far from it).
135 135
136 [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465 136 [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465
137 [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377 137 [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377
138 [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014 138 [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014
139 139
140 Inspired by vundle, antigen can pull oh-my-zsh style plugins from various github 140 Inspired by vundle, antigen can pull oh-my-zsh style plugins from various github
141 repositories. You are not limited to use plugins from the oh-my-zsh repository 141 repositories. You are not limited to use plugins from the oh-my-zsh repository
142 only and you don't need to maintain your own fork and pull from upstream every 142 only and you don't need to maintain your own fork and pull from upstream every
143 now and then. I actually encourage you to grab plugins and scripts from various 143 now and then. I actually encourage you to grab plugins and scripts from various
144 sources, straight from the authors, before they even submit it to oh-my-zsh as a 144 sources, straight from the authors, before they even submit it to oh-my-zsh as a
145 pull request. 145 pull request.
146 146
147 Antigen also lets you switch the prompt theme with one command, just like that 147 Antigen also lets you switch the prompt theme with one command, just like that
148 148
149 antigen-theme candy 149 antigen-theme candy
150 150
151 and your prompt is changed, just for this session of course (unless you put this 151 and your prompt is changed, just for this session of course (unless you put this
152 line in your `.zshrc`). 152 line in your `.zshrc`).
153 153
154 ## Commands 154 ## Commands
155 155
156 The following are the commands provided by antigen. Note that the `-` in the 156 The following are the commands provided by antigen. Note that the `-` in the
157 following commands can be replaced with a space. You can write `antigen-bundle 157 following commands can be replaced with a space. You can write `antigen-bundle
158 ...` as `antigen bundle ...` and get away with it. For more details see the help 158 ...` as `antigen bundle ...` and get away with it. For more details see the help
159 on `antigen` command further down in this section. 159 on `antigen` command further down in this section.
160 160
161 ### antigen-bundle 161 ### antigen-bundle
162 162
163 This command tells antigen to install (if not already installed) and load the 163 This command tells antigen to install (if not already installed) and load the
164 given plugin. The simplest usage follows the following syntax. 164 given plugin. The simplest usage follows the following syntax.
165 165
166 antigen-bundle <plugin-name> 166 antigen-bundle <plugin-name>
167 167
168 This will install and load the `plugins/<name>` directory from [robbyrussell's 168 This will install and load the `plugins/<name>` directory from [robbyrussell's
169 oh-my-zsh][oh-my-zsh] (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`). 169 oh-my-zsh][oh-my-zsh] (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`).
170 170
171 However, the above is just syntax sugar for the extended syntax of the 171 However, the above is just syntax sugar for the extended syntax of the
172 `antigen-bundle` command. 172 `antigen-bundle` command.
173 173
174 antigen-bundle [<url> [<loc>]] 174 antigen-bundle [<url> [<loc>]]
175 175
176 where `<url>` is the repository url and it defaults to [robbyrussell's 176 where `<url>` is the repository url and it defaults to [robbyrussell's
177 oh-my-zsh][oh-my-zsh] repo (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL` 177 oh-my-zsh][oh-my-zsh] repo (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`
178 discussed further down). `<loc>` is the path under this repository which has the 178 discussed further down). `<loc>` is the path under this repository which has the
179 zsh plugin. This is typically the directory that contains a `*.plugin.zsh` file, 179 zsh plugin. This is typically the directory that contains a `*.plugin.zsh` file,
180 but it could contain a completion file or just many `*.zsh` files to be sourced. 180 but it could contain a completion file or just many `*.zsh` files to be sourced.
181 `<loc>` defaults to `/`, which indicates the repository itself is a plugin. 181 `<loc>` defaults to `/`, which indicates the repository itself is a plugin.
182 182
183 An example invocation would be 183 An example invocation would be
184 184
185 # The following is the same as `antigen-bundle ant`. But for demonstration 185 # The following is the same as `antigen-bundle ant`. But for demonstration
186 # purposes, we use the extended syntax here. 186 # purposes, we use the extended syntax here.
187 antigen-bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant 187 antigen-bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant
188 188
189 This would install the ant plugin from robbyrussell's oh-my-zsh repo. Of course, 189 This would install the ant plugin from robbyrussell's oh-my-zsh repo. Of course,
190 github url's can be shortened. 190 github url's can be shortened.
191 191
192 antigen-bundle robbyrussell/oh-my-zsh plugins/ant 192 antigen-bundle robbyrussell/oh-my-zsh plugins/ant
193 193
194 And since this repo is the default, even that isn't necessary. But we can't 194 And since this repo is the default, even that isn't necessary. But we can't
195 specify the `loc` without giving the first argument. 195 specify the `loc` without giving the first argument.
196 196
197 For this and a few other reasons, `antigen-bundle` also supports a simple 197 For this and a few other reasons, `antigen-bundle` also supports a simple
198 keyword argument syntax, using which we can rewrite the above as 198 keyword argument syntax, using which we can rewrite the above as
199 199
200 antigen-bundle --loc=plugins/ant 200 antigen-bundle --loc=plugins/ant
201 201
202 Which picks up the default for the `url` argument, and uses the `loc` given to 202 Which picks up the default for the `url` argument, and uses the `loc` given to
203 it. 203 it.
204 204
205 *Note* that you can mix and match positional and keyword arguments. But you 205 *Note* that you can mix and match positional and keyword arguments. But you
206 can't have positional arguments after keyword arguments. 206 can't have positional arguments after keyword arguments.
207 207
208 antigen-bundle robbyrussell/oh-my-zsh --loc=plugins/ant 208 antigen-bundle robbyrussell/oh-my-zsh --loc=plugins/ant
209 209
210 And keyword arguments don't care about the order in which the arguments are 210 And keyword arguments don't care about the order in which the arguments are
211 specified. The following is perfectly valid. 211 specified. The following is perfectly valid.
212 212
213 antigen-bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh 213 antigen-bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh
214 214
215 You can also specify a local directory on your file system as a bundle. In this 215 You can also specify a local directory on your file system as a bundle. In this
216 case, make sure the path you give is the absolute path (i.e., starts with a 216 case, make sure the path you give is the absolute path (i.e., starts with a
217 `/`). Relative paths are not supported. If the repo you gave is a local 217 `/`). Relative paths are not supported. If the repo you gave is a local
218 directory path, then it is not necessary that this path is a git repo. Please 218 directory path, then it is not necessary that this path is a git repo. Please
219 refer to the notes on `--no-local-clone` below. 219 refer to the notes on `--no-local-clone` below.
220 220
221 This command can also be used from your shell environment. This allows you to 221 This command can also be used from your shell environment. This allows you to
222 install plugins on the fly and try them out. Of course if you want a bundle to 222 install plugins on the fly and try them out. Of course if you want a bundle to
223 be available every time you open a shell, put it in your `.zshrc`. 223 be available every time you open a shell, put it in your `.zshrc`.
224 224
225 Other keyword-only arguments accepted: 225 Other keyword-only arguments accepted:
226 226
227 `--branch={git-branch-name}` &mdash; Specify the branch of the git repo to be 227 `--branch={git-branch-name}` &mdash; Specify the branch of the git repo to be
228 used for this bundle (without the braces of course). The default is whatever 228 used for this bundle (without the braces of course). The default is whatever
229 branch the clone comes with, which is usually `master`. For example, 229 branch the clone comes with, which is usually `master`. For example,
230 230
231 antigen-bundle github-user/repo --branch=develop 231 antigen-bundle github-user/repo --branch=develop
232 232
233 This will get the plugin as in the branch `develop`. 233 This will get the plugin as in the branch `develop`.
234 234
235 Note that if you specify two plugins to be loaded from the same git repo, but 235 Note that if you specify two plugins to be loaded from the same git repo, but
236 different branches, then two separate clones of this repo will be maintained. 236 different branches, then two separate clones of this repo will be maintained.
237 This is a small implementation detail and shouldn't influence you in any way. 237 This is a small implementation detail and shouldn't influence you in any way.
238 238
239 `--no-local-clone` &mdash; This command can be useful if you are developing a 239 `--no-local-clone` &mdash; This command can be useful if you are developing a
240 plugin and already have a clone on your local file system. If this argument is 240 plugin and already have a clone on your local file system. If this argument is
241 not given, even if the given repo url is a local path, a clone is made in the 241 not given, even if the given repo url is a local path, a clone is made in the
242 `$ADOTDIR/repos`, and the plugin is loaded from that clone. But, if you give 242 `$ADOTDIR/repos`, and the plugin is loaded from that clone. But, if you give
243 this argument, the plugin is sourced straight from the repo location, without 243 this argument, the plugin is sourced straight from the repo location, without
244 creating a clone. For example, 244 creating a clone. For example,
245 245
246 antigen-bundle /absolute/path/to/the/plugin --no-local-clone 246 antigen-bundle /absolute/path/to/the/plugin --no-local-clone
247 247
248 Note that if the repo url is *not* an absolute local path or a branch has been 248 Note that if the repo url is *not* an absolute local path or a branch has been
249 specified with the `--branch` option, this argument has no effect. That is, 249 specified with the `--branch` option, this argument has no effect. That is,
250 for this option to have any affect, the repo url must be an absolute local path 250 for this option to have any affect, the repo url must be an absolute local path
251 and no `--branch` should be specified. 251 and no `--branch` should be specified.
252 252
253 Also, if the local path given as the url is not a git repo, then this 253 Also, if the local path given as the url is not a git repo, then this
254 argument is forced as it doesn't makes sense to *clone* something that's not a 254 argument is forced as it doesn't makes sense to *clone* something that's not a
255 git repo. This property can be used to load any utility scripts you have in your 255 git repo. This property can be used to load any utility scripts you have in your
256 dotfiles repo. For example, 256 dotfiles repo. For example,
257 257
258 antigen-bundle $HOME/dotfiles/oh-my-zsh/custom 258 antigen-bundle $HOME/dotfiles/oh-my-zsh/custom
259 259
260 In addition to the above discussed arguments, `antigen-bundle` also takes a 260 In addition to the above discussed arguments, `antigen-bundle` also takes a
261 `btype` keyword-only argument, that is used internally. You shouldn't be 261 `btype` keyword-only argument, that is used internally. You shouldn't be
262 concerned with this argument, its only used internally and will probably go away 262 concerned with this argument, its only used internally and will probably go away
263 in the future. It indicates whether the bundle is a theme or a simple plugin. 263 in the future. It indicates whether the bundle is a theme or a simple plugin.
264 264
265 ### antigen-bundles 265 ### antigen-bundles
266 266
267 If you have a fair number of bundles, using the `antigen-bundle` command can 267 If you have a fair number of bundles, using the `antigen-bundle` command can
268 look cumbersome. You can use the `antigen-bundles` command to *bulk* define 268 look cumbersome. You can use the `antigen-bundles` command to *bulk* define
269 bundles instead of individual calls to `antigen-bundle`. 269 bundles instead of individual calls to `antigen-bundle`.
270 270
271 Usage is pretty straightforward. Just pipe the bundle specifications, just as 271 Usage is pretty straightforward. Just pipe the bundle specifications, just as
272 you would give to the `antigen-bundle` command, one per line, into the 272 you would give to the `antigen-bundle` command, one per line, into the
273 `antigen-bundles` command. The easiest way to do this, is using the heredoc 273 `antigen-bundles` command. The easiest way to do this, is using the heredoc
274 syntax. 274 syntax.
275 275
276 antigen-bundles <<EOBUNDLES 276 antigen-bundles <<EOBUNDLES
277 # Guess what to install when running an unknown command. 277 # Guess what to install when running an unknown command.
278 command-not-found 278 command-not-found
279 279
280 # The heroku tool helper plugin. 280 # The heroku tool helper plugin.
281 heroku 281 heroku
282 282
283 EOBUNDLES 283 EOBUNDLES
284 284
285 This is equivalent to 285 This is equivalent to
286 286
287 antigen-bundle command-not-found 287 antigen-bundle command-not-found
288 antigen-bundle heroku 288 antigen-bundle heroku
289 289
290 Of course, as you can see, from the lines piped to `antigen-bundles`, empty 290 Of course, as you can see, from the lines piped to `antigen-bundles`, empty
291 lines and those starting with a `#` are ignored. The rest are passed to 291 lines and those starting with a `#` are ignored. The rest are passed to
292 `antigen-bundle` without any quoting rules applied. They are actually `eval`-ed 292 `antigen-bundle` without any quoting rules applied. They are actually `eval`-ed
293 with the `antigen-bundle` command. See the source if you want to really 293 with the `antigen-bundle` command. See the source if you want to really
294 understand how it works. Its a very small function. 294 understand how it works. Its a very small function.
295 295
296 ### antigen-update 296 ### antigen-update
297 297
298 This is something you might not want to put in your `.zshrc`. Instead, run it 298 This is something you might not want to put in your `.zshrc`. Instead, run it
299 occasionally to update all your plugins. It doesn't take any arguments. 299 occasionally to update all your plugins. It doesn't take any arguments.
300 300
301 antigen-update 301 antigen-update
302 302
303 Please note that the updates that are downloaded are not immediately available. 303 Please note that the updates that are downloaded are not immediately available.
304 You have to open a new shell to be able to see the changes. This is a limitation 304 You have to open a new shell to be able to see the changes. This is a limitation
305 by design since reloading all the plugins *might* have some nasty side effects 305 by design since reloading all the plugins *might* have some nasty side effects
306 that may not be immediately apparent. Let's just say it can make your shell act 306 that may not be immediately apparent. Let's just say it can make your shell act
307 real quirky. 307 real quirky.
308 308
309 **Please note**: This command is not for updating *antigen* itself. Its for 309 **Please note**: This command is not for updating *antigen* itself. Its for
310 updating the bundles you are using with antigen. To update your copy of antigen, 310 updating the bundles you are using with antigen. To update your copy of antigen,
311 use the `selfupdate` command described further below. 311 use the `selfupdate` command described further below.
312 312
313 ### antigen-revert <sup>&alpha;</sup> 313 ### antigen-revert <sup>&alpha;</sup>
314 314
315 Reverts the state of all your plugins to how they were before the last 315 Reverts the state of all your plugins to how they were before the last
316 `antigen-update`. This command is currently experimental, so don't rely too much 316 `antigen-update`. This command is currently experimental, so don't rely too much
317 on it. There is a test for it, and it passes, so it should work fine though. 317 on it. There is a test for it, and it passes, so it should work fine though.
318 318
319 Takes no options. 319 Takes no options.
320 320
321 Insider detail: The information for reverting is stored in 321 Insider detail: The information for reverting is stored in
322 `$ADOTDIR/revert-info` file. If its not present, reverting is not possible. 322 `$ADOTDIR/revert-info` file. If its not present, reverting is not possible.
323 323
324 ### antigen-list 324 ### antigen-list
325 325
326 Use this command to list out the currently *loaded* plugins. Keep in mind that 326 Use this command to list out the currently *loaded* plugins. Keep in mind that
327 this includes any bundles installed on-the-fly. 327 this includes any bundles installed on-the-fly.
328 328
329 Takes no arguments. Gives out four entries per line of output, denoting the 329 Takes no arguments. Gives out four entries per line of output, denoting the
330 following fields of each bundle. 330 following fields of each bundle.
331 331
332 <repo-url> <loc> <btype> <has-local-clone?> 332 <repo-url> <loc> <btype> <has-local-clone?>
333 333
334 The `btype` field is an internal detail, that specifies if the bundle is a 334 The `btype` field is an internal detail, that specifies if the bundle is a
335 `plugin` or a `theme`. 335 `plugin` or a `theme`.
336 336
337 The final field is `true` or `false` reflecting whether there is a local clone 337 The final field is `true` or `false` reflecting whether there is a local clone
338 for this bundle. 338 for this bundle.
339 339
340 ### antigen-cleanup 340 ### antigen-cleanup
341 341
342 Used to clean up the clones of repos which are not used by any plugins currently 342 Used to clean up the clones of repos which are not used by any plugins currently
343 loaded. It takes no arguments. When run, it lists out the repo-clones that are 343 loaded. It takes no arguments. When run, it lists out the repo-clones that are
344 available but are not used by any plugin *currently loaded*. 344 available but are not used by any plugin *currently loaded*.
345 345
346 This command, by default asks for confirmation before deleting the unused 346 This command, by default asks for confirmation before deleting the unused
347 clones. If the `--force` argument is given, then this confirmation is not asked. 347 clones. If the `--force` argument is given, then this confirmation is not asked.
348 It straight away deletes all the unused clones. This option makes this command 348 It straight away deletes all the unused clones. This option makes this command
349 usable in a non-interactive fashion. 349 usable in a non-interactive fashion.
350 350
351 ### antigen-lib 351 ### antigen-lib
352 352
353 This is a shortcut to 353 This is (almost) the same as
354 354
355 antigen-bundle --loc=lib 355 antigen-bundle --loc=lib
356 356
357 So, it basically installs the oh-my-zsh's library as a bundle. 357 So, it basically installs the oh-my-zsh's library as a bundle.
358 358
359 One other thing it does is that some oh-my-zsh plugins expect a `$ZSH` set to
360 the full path of the oh-my-zsh clone being used. This is also set to the
361 correct path, if not already set to something else.
362
359 Please note that this assumes that the `ANTIGEN_DEFAULT_REPO_URL` is set to the 363 Please note that this assumes that the `ANTIGEN_DEFAULT_REPO_URL` is set to the
360 oh-my-zsh repo or a fork of that repo. If you want to specify the `url` too, 364 oh-my-zsh repo or a fork of that repo. If you want to specify the `url` too,
361 then you can't use the `antigen-lib` short cut. You have to do that directly 365 then you can't use the `antigen-lib` short cut. You have to do that directly
362 with the `antigen-bundle` command. 366 with the `antigen-bundle` command.
363 367
364 This is present only for legacy reasons and *might* (or might not) be removed in 368 This is present to ease dealing with oh-my-zsh plugins.
365 the future.
366 369
367 Use 370 Use
368 371
369 antigen-lib 372 antigen-lib
370 373
371 in your `.zshrc`, before any `antigen-bundle` declarations. It takes no 374 in your `.zshrc`, before any `antigen-bundle` declarations. It takes no
372 arguments. 375 arguments.
373 376
374 ### antigen-prezto-lib <sup>&alpha;</sup> 377 ### antigen-prezto-lib <sup>&alpha;</sup>
375 378
376 This is (almost, but not quite) the same as doing, 379 This is (almost, but not quite) the same as doing,
377 380
378 antigen-bundle sorin-ionescu/prezto 381 antigen-bundle sorin-ionescu/prezto
379 382
380 That is, initializes the canonical repo of the prezto framework. Please note 383 That is, initializes the canonical repo of the prezto framework. Please note
381 that prezto support is very new and experimental in antigen. If you find any 384 that prezto support is very new and experimental in antigen. If you find any
382 bugs, please report over on github issues. 385 bugs, please report over on github issues.
383 386
384 ### antigen-theme 387 ### antigen-theme
385 388
386 Used for switching the prompt theme. Invoke it with the name of the theme you 389 Used for switching the prompt theme. Invoke it with the name of the theme you
387 want to use. 390 want to use.
388 391
389 antigen-theme fox 392 antigen-theme fox
390 393
391 This will get the theme file located at `themes/fox.zsh-theme` in the repo 394 This will get the theme file located at `themes/fox.zsh-theme` in the repo
392 specified by `ANTIGEN_DEFAULT_REPO_URL`. 395 specified by `ANTIGEN_DEFAULT_REPO_URL`.
393 396
394 To pull themes from other repositories, use `antigen-theme` just like 397 To pull themes from other repositories, use `antigen-theme` just like
395 `antigen-bundle`. Exactly the same, just make sure the `url` and `loc` 398 `antigen-bundle`. Exactly the same, just make sure the `url` and `loc`
396 combination point to a theme file, having a `.zsh-theme` extension. 399 combination point to a theme file, having a `.zsh-theme` extension.
397 400
398 For example, 401 For example,
399 402
400 antigen-theme robbyrussell/oh-my-zsh themes/apple 403 antigen-theme robbyrussell/oh-my-zsh themes/apple
401 404
402 Will pull the apple theme from the canonical oh-my-zsh repo. Also, note that the 405 Will pull the apple theme from the canonical oh-my-zsh repo. Also, note that the
403 `.zsh-theme` extension is not present. It can be given, its optional. 406 `.zsh-theme` extension is not present. It can be given, its optional.
404 407
405 You can use this command to change your theme on the fly in your shell. Go on, 408 You can use this command to change your theme on the fly in your shell. Go on,
406 try out a few themes in your shell before you set it in your `.zshrc`. 409 try out a few themes in your shell before you set it in your `.zshrc`.
407 410
408 **Note**: Some themes use functions that are loaded by `antigen-lib`. So, to 411 **Note**: Some themes use functions that are loaded by `antigen-lib`. So, to
409 avoid any trouble, run `antigen-lib` if you haven't already before experimenting 412 avoid any trouble, run `antigen-lib` if you haven't already before experimenting
410 with themes. If you have `antigen-lib` in your `.zshrc`, you're covered. 413 with themes. If you have `antigen-lib` in your `.zshrc`, you're covered.
411 414
412 **Note**: Do *not* provide the `--btype` argument to `antigen-theme`. Its an 415 **Note**: Do *not* provide the `--btype` argument to `antigen-theme`. Its an
413 internal argument. 416 internal argument.
414 417
415 ### antigen-apply 418 ### antigen-apply
416 419
417 You have to add this command after defining all bundles you need, in your zshrc. 420 You have to add this command after defining all bundles you need, in your zshrc.
418 The completions defined by your bundles will be loaded at this step. 421 The completions defined by your bundles will be loaded at this step.
419 422
420 It is possible to load completions as and when a bundle is specified with the 423 It is possible to load completions as and when a bundle is specified with the
421 bundle command, in which case this command would not be necessary. But loading 424 bundle command, in which case this command would not be necessary. But loading
422 the completions is a time-consuming process, so if the completions were loaded 425 the completions is a time-consuming process, so if the completions were loaded
423 at every call to `antigen-bundle`, your shell will start noticeably slow when 426 at every call to `antigen-bundle`, your shell will start noticeably slow when
424 you have a good number of bundle specifications. 427 you have a good number of bundle specifications.
425 428
426 However, if you can suggest a way so that this would not be necessary, I am very 429 However, if you can suggest a way so that this would not be necessary, I am very
427 interested in discussing it. Please open up an issue with your details. Thanks. 430 interested in discussing it. Please open up an issue with your details. Thanks.
428 431
429 ### antigen-snapshot <sup>&alpha;</sup> 432 ### antigen-snapshot <sup>&alpha;</sup>
430 433
431 Creates a snapshot of all the clones you currently have *active* including the 434 Creates a snapshot of all the clones you currently have *active* including the
432 git version hash they are at and save it to a snapshot file. *Active* means, the 435 git version hash they are at and save it to a snapshot file. *Active* means, the
433 clones for those listed by `antigen-cleanup` are not included in the snapshot. 436 clones for those listed by `antigen-cleanup` are not included in the snapshot.
434 437
435 Takes one optional argument, the file name in which the snapshot is to be saved. 438 Takes one optional argument, the file name in which the snapshot is to be saved.
436 Defaults to `antigen-snapshot`. 439 Defaults to `antigen-snapshot`.
437 440
438 **Note**: The snapshot currently *only* contains the details of those bundles 441 **Note**: The snapshot currently *only* contains the details of those bundles
439 that have a clone. That is, bundles that have `--no-local-clone` set or are 442 that have a clone. That is, bundles that have `--no-local-clone` set or are
440 directly sourced from your file system (without a git repo), are not recorded 443 directly sourced from your file system (without a git repo), are not recorded
441 in the snapshot file. 444 in the snapshot file.
442 445
443 ### antigen-restore <sup>&alpha;</sup> 446 ### antigen-restore <sup>&alpha;</sup>
444 447
445 Restore the bundles state as specified in the snapshot. Takes one required 448 Restore the bundles state as specified in the snapshot. Takes one required
446 argument, the snapshot file name to read. 449 argument, the snapshot file name to read.
447 450
448 Although it restores the clones of the repos specified in the snapshot file, any 451 Although it restores the clones of the repos specified in the snapshot file, any
449 other clones present in your environment are not touched. This behavior may 452 other clones present in your environment are not touched. This behavior may
450 change in the future. 453 change in the future.
451 454
452 ### antigen-selfupdate 455 ### antigen-selfupdate
453 456
454 Use this command to update your copy of antigen. It basically does a `git pull` 457 Use this command to update your copy of antigen. It basically does a `git pull`
455 on your antigen's clone, *if* it is a git clone. Otherwise, it doesn't do 458 on your antigen's clone, *if* it is a git clone. Otherwise, it doesn't do
456 anything. 459 anything.
457 460
458 Takes no options. 461 Takes no options.
459 462
460 ### antigen-help 463 ### antigen-help
461 464
462 This exists so that there can be some help right in the command line. Currently 465 This exists so that there can be some help right in the command line. Currently
463 it doesn't provide much help other than redirecting you to the project page for 466 it doesn't provide much help other than redirecting you to the project page for
464 documentation. It is intended to provide more meaning and sub-command specific 467 documentation. It is intended to provide more meaning and sub-command specific
465 help in the future. 468 help in the future.
466 469
467 I could use some help here as I'm not that good at writing documentation that 470 I could use some help here as I'm not that good at writing documentation that
468 looks good as output on the command line. 471 looks good as output on the command line.
469 472
470 ### antigen 473 ### antigen
471 474
472 This is a parent command that mainly exists for convenience. This exists so the 475 This is a parent command that mainly exists for convenience. This exists so the
473 following two can be the same. 476 following two can be the same.
474 477
475 antigen-list 478 antigen-list
476 antigen list 479 antigen list
477 480
478 and 481 and
479 482
480 antigen-help 483 antigen-help
481 antigen help 484 antigen help
482 485
483 Because of this, we can create aliases like 486 Because of this, we can create aliases like
484 487
485 alias a=antigen 488 alias a=antigen
486 alias an=antigen 489 alias an=antigen
487 490
488 and run the antigen commands without making them look annoyingly long. 491 and run the antigen commands without making them look annoyingly long.
489 492
490 a bundle ruby 493 a bundle ruby
491 a theme candy 494 a theme candy
492 a list 495 a list
493 496
494 And even... 497 And even...
495 498
496 an update 499 an update
497 500
498 ## Configuration 501 ## Configuration
499 502
500 The following environment variables can be set to customize the behavior of 503 The following environment variables can be set to customize the behavior of
501 antigen. Make sure you set them *before* source-ing `antigen.zsh`. 504 antigen. Make sure you set them *before* source-ing `antigen.zsh`.
502 505
503 `ANTIGEN_DEFAULT_REPO_URL` &mdash; This is the default repository url that is 506 `ANTIGEN_DEFAULT_REPO_URL` &mdash; This is the default repository url that is
504 used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo, 507 used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo,
505 but you can set this to the fork url of your own fork. 508 but you can set this to the fork url of your own fork.
506 509
507 `ADOTDIR` &mdash; This directory is used to store all the repo clones, your 510 `ADOTDIR` &mdash; This directory is used to store all the repo clones, your
508 bundles, themes, caches and everything else antigen requires to run smoothly. 511 bundles, themes, caches and everything else antigen requires to run smoothly.
509 Defaults to `$HOME/.antigen`. 512 Defaults to `$HOME/.antigen`.
510 513
511 **Note**: `ANTIGEN_REPO_CACHE` & `ANTIGEN_BUNDLE_DIR` &mdash; These variables 514 **Note**: `ANTIGEN_REPO_CACHE` & `ANTIGEN_BUNDLE_DIR` &mdash; These variables
512 were used previously but are now removed. Please use `ADOTDIR` instead, as 515 were used previously but are now removed. Please use `ADOTDIR` instead, as
513 mentioned above. 516 mentioned above.
514 517
515 ## Running the tests 518 ## Running the tests
516 519
517 All the tests are in the `tests` folder and are run using the [cram][] test 520 All the tests are in the `tests` folder and are run using the [cram][] test
518 system. The latest version on that website, as of today is v0.5, which does not 521 system. The latest version on that website, as of today is v0.5, which does not
519 have the `--shell` argument which is required to run our tests. So, to get the 522 have the `--shell` argument which is required to run our tests. So, to get the
520 correct version of cram, run 523 correct version of cram, run
521 524
522 pip install -r requirements.txt 525 pip install -r requirements.txt
523 526
524 With that, once you have cram installed, you can run the tests as 527 With that, once you have cram installed, you can run the tests as
525 528
526 make 529 make
527 530
528 If you are making a feature addition, I'd really appreciate if you can add a 531 If you are making a feature addition, I'd really appreciate if you can add a
529 test for your feature. Even if you can add a test for an existing feature, that 532 test for your feature. Even if you can add a test for an existing feature, that
530 would be great as the tests are currently seriously lagging behind the full 533 would be great as the tests are currently seriously lagging behind the full
531 functionality of antigen. 534 functionality of antigen.
532 535
533 ## Notes on writing plugins 536 ## Notes on writing plugins
534 537
535 Most shell utilities/plugins are made up of just one file. For a plugin called 538 Most shell utilities/plugins are made up of just one file. For a plugin called
536 `awesomeness`, create a `awesomeness.plugin.zsh` and code away. 539 `awesomeness`, create a `awesomeness.plugin.zsh` and code away.
537 540
538 That said, even if you write a single file as a `.sh` file with the goodness you 541 That said, even if you write a single file as a `.sh` file with the goodness you
539 want to create, antigen will work just fine with it. The `*.plugin.zsh` way is 542 want to create, antigen will work just fine with it. The `*.plugin.zsh` way is
540 recommended by antigen, because it is widely used because of the [oh-my-zsh][] 543 recommended by antigen, because it is widely used because of the [oh-my-zsh][]
541 project. 544 project.
542 545
543 If you want to know how antigen loads the plugins, do continue. 546 If you want to know how antigen loads the plugins, do continue.
544 547
545 Firstly, antigen looks for a `*.plugin.zsh` file in the plugin directory. If 548 Firstly, antigen looks for a `*.plugin.zsh` file in the plugin directory. If
546 present, it will source *only* this script. Nothing else is sourced. This is for 549 present, it will source *only* this script. Nothing else is sourced. This is for
547 oh-my-zsh style plugins. 550 oh-my-zsh style plugins.
548 551
549 Secondly, it looks for a `init.zsh` file in the plugin directory. If present, it 552 Secondly, it looks for a `init.zsh` file in the plugin directory. If present, it
550 will source *only* this script. Nothing else is sourced. This is for prezto 553 will source *only* this script. Nothing else is sourced. This is for prezto
551 style modules. 554 style modules.
552 555
553 Otherwise, it looks for `*.zsh` files and if there are any, *all* of them are 556 Otherwise, it looks for `*.zsh` files and if there are any, *all* of them are
554 sourced. The order in which they are sourced is not currently defined. Please 557 sourced. The order in which they are sourced is not currently defined. Please
555 don't rely on this order. Nothing else is sourced after all the `*.zsh` scripts. 558 don't rely on this order. Nothing else is sourced after all the `*.zsh` scripts.
556 559
557 If no `*.zsh` files are present, it finally looks for any `*.sh` files and 560 If no `*.zsh` files are present, it finally looks for any `*.sh` files and
558 sources *all* of them. Again, the order in which they are sourced in not 561 sources *all* of them. Again, the order in which they are sourced in not
559 currently defined. 562 currently defined.
560 563
561 No matter which (or none) of the above happen to be sourced, this plugin 564 No matter which (or none) of the above happen to be sourced, this plugin
562 directory is added to the zsh's function path (`$fpath`) so that any completions 565 directory is added to the zsh's function path (`$fpath`) so that any completions
563 in it are loaded. 566 in it are loaded.
564 567
565 One exception to this rule is that if this plugin is a theme. In which case the 568 One exception to this rule is that if this plugin is a theme. In which case the
566 theme script is just sourced and nothing else is done. Not even adding to 569 theme script is just sourced and nothing else is done. Not even adding to
567 `$fpath`. 570 `$fpath`.
568 571
569 ## Meta 572 ## Meta
570 573
571 ### Helping out 574 ### Helping out
572 575
573 Antigen is licensed with the [MIT License][license]. To contribute, just fork, 576 Antigen is licensed with the [MIT License][license]. To contribute, just fork,
574 make changes and send a pull request. If its a rather long/complicated change, 577 make changes and send a pull request. If its a rather long/complicated change,
575 please consider opening an [issue][] first so we can discuss it out. 578 please consider opening an [issue][] first so we can discuss it out.
576 579
577 ### Feedback please 580 ### Feedback please
578 581
579 Any comments/suggestions/feedback welcome. Please say hello to me 582 Any comments/suggestions/feedback welcome. Please say hello to me
580 ([@sharat87][twitter]) on twitter. Or open an issue to discuss something 583 ([@sharat87][twitter]) on twitter. Or open an issue to discuss something
581 (anything!) about the project ;). 584 (anything!) about the project ;).
582 585
583 586
584 [Vundle]: https://github.com/gmarik/vundle 587 [Vundle]: https://github.com/gmarik/vundle
585 [page on themes]: https://github.com/robbyrussell/oh-my-zsh/wiki/Themes 588 [page on themes]: https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
586 [syntax highlighting plugin]: https://github.com/zsh-users/zsh-syntax-highlighting 589 [syntax highlighting plugin]: https://github.com/zsh-users/zsh-syntax-highlighting
587 [autoenv]: https://github.com/kennethreitz/autoenv 590 [autoenv]: https://github.com/kennethreitz/autoenv
588 [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh 591 [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh
589 [cram]: https://bitheap.org/cram/ 592 [cram]: https://bitheap.org/cram/
590 [issue]: https://github.com/zsh-users/antigen/issues 593 [issue]: https://github.com/zsh-users/antigen/issues
591 [license]: http://mit.sharats.me 594 [license]: http://mit.sharats.me
592 [twitter]: http://twitter.com/sharat87 595 [twitter]: http://twitter.com/sharat87
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 # Syntaxes 10 # Syntaxes
11 # antigen-bundle <url> [<loc>=/] 11 # antigen-bundle <url> [<loc>=/]
12 # Keyword only arguments: 12 # Keyword only arguments:
13 # branch - The branch of the repo to use for this bundle. 13 # branch - The branch of the repo to use for this bundle.
14 antigen-bundle () { 14 antigen-bundle () {
15 15
16 # Bundle spec arguments' default values. 16 # Bundle spec arguments' default values.
17 local url="$ANTIGEN_DEFAULT_REPO_URL" 17 local url="$ANTIGEN_DEFAULT_REPO_URL"
18 local loc=/ 18 local loc=/
19 local branch= 19 local branch=
20 local no_local_clone=false 20 local no_local_clone=false
21 local btype=plugin 21 local btype=plugin
22 22
23 # Parse the given arguments. (Will overwrite the above values). 23 # Parse the given arguments. (Will overwrite the above values).
24 eval "$(-antigen-parse-args \ 24 eval "$(-antigen-parse-args \
25 'url?, loc? ; branch:?, no-local-clone?, btype:?' \ 25 'url?, loc? ; branch:?, no-local-clone?, btype:?' \
26 "$@")" 26 "$@")"
27 27
28 # Check if url is just the plugin name. Super short syntax. 28 # Check if url is just the plugin name. Super short syntax.
29 if [[ "$url" != */* ]]; then 29 if [[ "$url" != */* ]]; then
30 loc="plugins/$url" 30 loc="plugins/$url"
31 url="$ANTIGEN_DEFAULT_REPO_URL" 31 url="$ANTIGEN_DEFAULT_REPO_URL"
32 fi 32 fi
33 33
34 # Resolve the url. 34 # Resolve the url.
35 url="$(-antigen-resolve-bundle-url "$url")" 35 url="$(-antigen-resolve-bundle-url "$url")"
36 36
37 # Add the branch information to the url. 37 # Add the branch information to the url.
38 if [[ ! -z $branch ]]; then 38 if [[ ! -z $branch ]]; then
39 url="$url|$branch" 39 url="$url|$branch"
40 fi 40 fi
41 41
42 # The `make_local_clone` variable better represents whether there should be 42 # The `make_local_clone` variable better represents whether there should be
43 # a local clone made. For cloning to be avoided, firstly, the `$url` should 43 # a local clone made. For cloning to be avoided, firstly, the `$url` should
44 # be an absolute local path and `$branch` should be empty. In addition to 44 # be an absolute local path and `$branch` should be empty. In addition to
45 # these two conditions, either the `--no-local-clone` option should be 45 # these two conditions, either the `--no-local-clone` option should be
46 # given, or `$url` should not a git repo. 46 # given, or `$url` should not a git repo.
47 local make_local_clone=true 47 local make_local_clone=true
48 if [[ $url == /* && -z $branch && 48 if [[ $url == /* && -z $branch &&
49 ( $no_local_clone == true || ! -d $url/.git ) ]]; then 49 ( $no_local_clone == true || ! -d $url/.git ) ]]; then
50 make_local_clone=false 50 make_local_clone=false
51 fi 51 fi
52 52
53 # Add the theme extension to `loc`, if this is a theme. 53 # Add the theme extension to `loc`, if this is a theme.
54 if [[ $btype == theme && $loc != *.zsh-theme ]]; then 54 if [[ $btype == theme && $loc != *.zsh-theme ]]; then
55 loc="$loc.zsh-theme" 55 loc="$loc.zsh-theme"
56 fi 56 fi
57 57
58 # Add it to the record. 58 # Add it to the record.
59 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" 59 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype"
60 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD $make_local_clone" 60 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD $make_local_clone"
61 61
62 # Ensure a clone exists for this repo, if needed. 62 # Ensure a clone exists for this repo, if needed.
63 if $make_local_clone; then 63 if $make_local_clone; then
64 -antigen-ensure-repo "$url" 64 -antigen-ensure-repo "$url"
65 fi 65 fi
66 66
67 # Load the plugin. 67 # Load the plugin.
68 -antigen-load "$url" "$loc" "$btype" "$make_local_clone" 68 -antigen-load "$url" "$loc" "$btype" "$make_local_clone"
69 69
70 } 70 }
71 71
72 -antigen-resolve-bundle-url () { 72 -antigen-resolve-bundle-url () {
73 # Given an acceptable short/full form of a bundle's repo url, this function 73 # Given an acceptable short/full form of a bundle's repo url, this function
74 # echoes the full form of the repo's clone url. 74 # echoes the full form of the repo's clone url.
75 75
76 local url="$1" 76 local url="$1"
77 77
78 # Expand short github url syntax: `username/reponame`. 78 # Expand short github url syntax: `username/reponame`.
79 if [[ $url != git://* && 79 if [[ $url != git://* &&
80 $url != https://* && 80 $url != https://* &&
81 $url != /* && 81 $url != /* &&
82 $url != git@github.com:*/* 82 $url != git@github.com:*/*
83 ]]; then 83 ]]; then
84 url="https://github.com/${url%.git}.git" 84 url="https://github.com/${url%.git}.git"
85 fi 85 fi
86 86
87 echo "$url" 87 echo "$url"
88 } 88 }
89 89
90 antigen-bundles () { 90 antigen-bundles () {
91 # Bulk add many bundles at one go. Empty lines and lines starting with a `#` 91 # Bulk add many bundles at one go. Empty lines and lines starting with a `#`
92 # are ignored. Everything else is given to `antigen-bundle` as is, no 92 # are ignored. Everything else is given to `antigen-bundle` as is, no
93 # quoting rules applied. 93 # quoting rules applied.
94 94
95 local line 95 local line
96 96
97 grep -v '^\s*$\|^#' | while read line; do 97 grep -v '^\s*$\|^#' | while read line; do
98 # Using `eval` so that we can use the shell-style quoting in each line 98 # Using `eval` so that we can use the shell-style quoting in each line
99 # piped to `antigen-bundles`. 99 # piped to `antigen-bundles`.
100 eval "antigen-bundle $line" 100 eval "antigen-bundle $line"
101 done 101 done
102 } 102 }
103 103
104 antigen-update () { 104 antigen-update () {
105 # Update your bundles, i.e., `git pull` in all the plugin repos. 105 # Update your bundles, i.e., `git pull` in all the plugin repos.
106 106
107 date > $ADOTDIR/revert-info 107 date > $ADOTDIR/revert-info
108 108
109 -antigen-echo-record | 109 -antigen-echo-record |
110 awk '$4 == "true" {print $1}' | 110 awk '$4 == "true" {print $1}' |
111 sort -u | 111 sort -u |
112 while read url; do 112 while read url; do
113 echo "**** Pulling $url" 113 echo "**** Pulling $url"
114 114
115 local clone_dir="$(-antigen-get-clone-dir "$url")" 115 local clone_dir="$(-antigen-get-clone-dir "$url")"
116 if [[ -d "$clone_dir" ]]; then 116 if [[ -d "$clone_dir" ]]; then
117 (echo -n "$clone_dir:" 117 (echo -n "$clone_dir:"
118 cd "$clone_dir" 118 cd "$clone_dir"
119 git rev-parse HEAD) >> $ADOTDIR/revert-info 119 git rev-parse HEAD) >> $ADOTDIR/revert-info
120 fi 120 fi
121 121
122 -antigen-ensure-repo "$url" --update --verbose 122 -antigen-ensure-repo "$url" --update --verbose
123 123
124 echo 124 echo
125 done 125 done
126 } 126 }
127 127
128 antigen-revert () { 128 antigen-revert () {
129 if ! [[ -f $ADOTDIR/revert-info ]]; then 129 if ! [[ -f $ADOTDIR/revert-info ]]; then
130 echo 'No revert information available. Cannot revert.' >&2 130 echo 'No revert information available. Cannot revert.' >&2
131 fi 131 fi
132 132
133 cat $ADOTDIR/revert-info | sed '1!p' | while read line; do 133 cat $ADOTDIR/revert-info | sed '1!p' | while read line; do
134 dir="$(echo "$line" | cut -d: -f1)" 134 dir="$(echo "$line" | cut -d: -f1)"
135 git --git-dir="$dir/.git" --work-tree="$dir" \ 135 git --git-dir="$dir/.git" --work-tree="$dir" \
136 checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null 136 checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null
137 done 137 done
138 138
139 echo "Reverted to state before running -update on $( 139 echo "Reverted to state before running -update on $(
140 cat $ADOTDIR/revert-info | sed -n 1p)." 140 cat $ADOTDIR/revert-info | sed -n 1p)."
141 } 141 }
142 142
143 -antigen-get-clone-dir () { 143 -antigen-get-clone-dir () {
144 # Takes a repo url and gives out the path that this url needs to be cloned 144 # Takes a repo url and gives out the path that this url needs to be cloned
145 # to. Doesn't actually clone anything. 145 # to. Doesn't actually clone anything.
146 echo -n $ADOTDIR/repos/ 146 echo -n $ADOTDIR/repos/
147 147
148 if [[ "$1" == "https://github.com/sorin-ionescu/prezto.git" ]]; then 148 if [[ "$1" == "https://github.com/sorin-ionescu/prezto.git" ]]; then
149 # Prezto's directory *has* to be `.zprezto`. 149 # Prezto's directory *has* to be `.zprezto`.
150 echo .zprezto 150 echo .zprezto
151 151
152 else 152 else
153 echo "$1" | sed \ 153 echo "$1" | sed \
154 -e 's./.-SLASH-.g' \ 154 -e 's./.-SLASH-.g' \
155 -e 's.:.-COLON-.g' \ 155 -e 's.:.-COLON-.g' \
156 -e 's.|.-PIPE-.g' 156 -e 's.|.-PIPE-.g'
157 157
158 fi 158 fi
159 } 159 }
160 160
161 -antigen-get-clone-url () { 161 -antigen-get-clone-url () {
162 # Takes a repo's clone dir and gives out the repo's original url that was 162 # Takes a repo's clone dir and gives out the repo's original url that was
163 # used to create the given directory path. 163 # used to create the given directory path.
164 164
165 if [[ "$1" == ".zprezto" ]]; then 165 if [[ "$1" == ".zprezto" ]]; then
166 # Prezto's (in `.zprezto`), is assumed to be from `sorin-ionescu`'s 166 # Prezto's (in `.zprezto`), is assumed to be from `sorin-ionescu`'s
167 # remote. 167 # remote.
168 echo https://github.com/sorin-ionescu/prezto.git 168 echo https://github.com/sorin-ionescu/prezto.git
169 169
170 else 170 else
171 echo "$1" | sed \ 171 echo "$1" | sed \
172 -e "s:^$ADOTDIR/repos/::" \ 172 -e "s:^$ADOTDIR/repos/::" \
173 -e 's.-SLASH-./.g' \ 173 -e 's.-SLASH-./.g' \
174 -e 's.-COLON-.:.g' \ 174 -e 's.-COLON-.:.g' \
175 -e 's.-PIPE-.|.g' 175 -e 's.-PIPE-.|.g'
176 176
177 fi 177 fi
178 } 178 }
179 179
180 -antigen-ensure-repo () { 180 -antigen-ensure-repo () {
181 181
182 # Ensure that a clone exists for the given repo url and branch. If the first 182 # Ensure that a clone exists for the given repo url and branch. If the first
183 # argument is `--update` and if a clone already exists for the given repo 183 # argument is `--update` and if a clone already exists for the given repo
184 # and branch, it is pull-ed, i.e., updated. 184 # and branch, it is pull-ed, i.e., updated.
185 185
186 # Argument defaults. 186 # Argument defaults.
187 # The url. No sane default for this, so just empty. 187 # The url. No sane default for this, so just empty.
188 local url= 188 local url=
189 # Check if we have to update. 189 # Check if we have to update.
190 local update=false 190 local update=false
191 # Verbose output. 191 # Verbose output.
192 local verbose=false 192 local verbose=false
193 193
194 eval "$(-antigen-parse-args 'url ; update?, verbose?' "$@")" 194 eval "$(-antigen-parse-args 'url ; update?, verbose?' "$@")"
195 shift $# 195 shift $#
196 196
197 # Get the clone's directory as per the given repo url and branch. 197 # Get the clone's directory as per the given repo url and branch.
198 local clone_dir="$(-antigen-get-clone-dir $url)" 198 local clone_dir="$(-antigen-get-clone-dir $url)"
199 199
200 # A temporary function wrapping the `git` command with repeated arguments. 200 # A temporary function wrapping the `git` command with repeated arguments.
201 --plugin-git () { 201 --plugin-git () {
202 (cd "$clone_dir" && git --no-pager "$@") 202 (cd "$clone_dir" && git --no-pager "$@")
203 } 203 }
204 204
205 # Clone if it doesn't already exist. 205 # Clone if it doesn't already exist.
206 if [[ ! -d $clone_dir ]]; then 206 if [[ ! -d $clone_dir ]]; then
207 git clone --recursive "${url%|*}" "$clone_dir" 207 git clone --recursive "${url%|*}" "$clone_dir"
208 elif $update; then 208 elif $update; then
209 # Save current revision. 209 # Save current revision.
210 local old_rev="$(--plugin-git rev-parse HEAD)" 210 local old_rev="$(--plugin-git rev-parse HEAD)"
211 # Pull changes if update requested. 211 # Pull changes if update requested.
212 --plugin-git pull 212 --plugin-git pull
213 # Update submodules. 213 # Update submodules.
214 --plugin-git submodule update --recursive 214 --plugin-git submodule update --recursive
215 # Get the new revision. 215 # Get the new revision.
216 local new_rev="$(--plugin-git rev-parse HEAD)" 216 local new_rev="$(--plugin-git rev-parse HEAD)"
217 fi 217 fi
218 218
219 # If its a specific branch that we want, checkout that branch. 219 # If its a specific branch that we want, checkout that branch.
220 if [[ $url == *\|* ]]; then 220 if [[ $url == *\|* ]]; then
221 local current_branch=${$(--plugin-git symbolic-ref HEAD)##refs/heads/} 221 local current_branch=${$(--plugin-git symbolic-ref HEAD)##refs/heads/}
222 local requested_branch="${url#*|}" 222 local requested_branch="${url#*|}"
223 # Only do the checkout when we are not already on the branch. 223 # Only do the checkout when we are not already on the branch.
224 [[ $requested_branch != $current_branch ]] && 224 [[ $requested_branch != $current_branch ]] &&
225 --plugin-git checkout $requested_branch 225 --plugin-git checkout $requested_branch
226 fi 226 fi
227 227
228 if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then 228 if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then
229 echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. 229 echo Updated from ${old_rev:0:7} to ${new_rev:0:7}.
230 if $verbose; then 230 if $verbose; then
231 --plugin-git log --oneline --reverse --no-merges --stat '@{1}..' 231 --plugin-git log --oneline --reverse --no-merges --stat '@{1}..'
232 fi 232 fi
233 fi 233 fi
234 234
235 # Remove the temporary git wrapper function. 235 # Remove the temporary git wrapper function.
236 unfunction -- --plugin-git 236 unfunction -- --plugin-git
237 237
238 } 238 }
239 239
240 -antigen-load () { 240 -antigen-load () {
241 241
242 local url="$1" 242 local url="$1"
243 local loc="$2" 243 local loc="$2"
244 local btype="$3" 244 local btype="$3"
245 local make_local_clone="$4" 245 local make_local_clone="$4"
246 246
247 # The full location where the plugin is located. 247 # The full location where the plugin is located.
248 local location 248 local location
249 if $make_local_clone; then 249 if $make_local_clone; then
250 location="$(-antigen-get-clone-dir "$url")/$loc" 250 location="$(-antigen-get-clone-dir "$url")/$loc"
251 else 251 else
252 location="$url" 252 location="$url"
253 fi 253 fi
254 254
255 if [[ $btype == theme ]]; then 255 if [[ $btype == theme ]]; then
256 256
257 # Of course, if its a theme, the location would point to the script 257 # Of course, if its a theme, the location would point to the script
258 # file. 258 # file.
259 source "$location" 259 source "$location"
260 260
261 else 261 else
262 262
263 # Source the plugin script. 263 # Source the plugin script.
264 # FIXME: I don't know. Looks very very ugly. Needs a better 264 # FIXME: I don't know. Looks very very ugly. Needs a better
265 # implementation once tests are ready. 265 # implementation once tests are ready.
266 local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" 266 local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')"
267 267
268 if [[ -f $location/$script_loc ]]; then 268 if [[ -f $location/$script_loc ]]; then
269 # If we have a `*.plugin.zsh`, source it. 269 # If we have a `*.plugin.zsh`, source it.
270 source "$location/$script_loc" 270 source "$location/$script_loc"
271 271
272 elif [[ -f $location/init.zsh ]]; then 272 elif [[ -f $location/init.zsh ]]; then
273 # If we have a `init.zsh` 273 # If we have a `init.zsh`
274 if (( $+functions[pmodload] )); then 274 if (( $+functions[pmodload] )); then
275 # If pmodload is defined pmodload the module. Remove `modules/` 275 # If pmodload is defined pmodload the module. Remove `modules/`
276 # from loc to find module name. 276 # from loc to find module name.
277 pmodload "${loc#modules/}" 277 pmodload "${loc#modules/}"
278 else 278 else
279 # Otherwise source it. 279 # Otherwise source it.
280 source "$location/init.zsh" 280 source "$location/init.zsh"
281 fi 281 fi
282 282
283 elif ls "$location" | grep -qm1 '\.zsh$'; then 283 elif ls "$location" | grep -qm1 '\.zsh$'; then
284 # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` 284 # If there is no `*.plugin.zsh` file, source *all* the `*.zsh`
285 # files. 285 # files.
286 for script ($location/*.zsh(N)) source "$script" 286 for script ($location/*.zsh(N)) source "$script"
287 287
288 elif ls "$location" | grep -qm1 '\.sh$'; then 288 elif ls "$location" | grep -qm1 '\.sh$'; then
289 # If there are no `*.zsh` files either, we look for and source any 289 # If there are no `*.zsh` files either, we look for and source any
290 # `*.sh` files instead. 290 # `*.sh` files instead.
291 for script ($location/*.sh(N)) source "$script" 291 for script ($location/*.sh(N)) source "$script"
292 292
293 fi 293 fi
294 294
295 # Add to $fpath, for completion(s). 295 # Add to $fpath, for completion(s).
296 fpath=($location $fpath) 296 fpath=($location $fpath)
297 297
298 fi 298 fi
299 299
300 } 300 }
301 301
302 # Update (with `git pull`) antigen itself. 302 # Update (with `git pull`) antigen itself.
303 # TODO: Once update is finished, show a summary of the new commits, as a kind of 303 # TODO: Once update is finished, show a summary of the new commits, as a kind of
304 # "what's new" message. 304 # "what's new" message.
305 antigen-selfupdate () { 305 antigen-selfupdate () {
306 ( cd $_ANTIGEN_INSTALL_DIR 306 ( cd $_ANTIGEN_INSTALL_DIR
307 if [[ ! -d .git ]]; then 307 if [[ ! -d .git ]]; then
308 echo "Your copy of antigen doesn't appear to be a git clone. " \ 308 echo "Your copy of antigen doesn't appear to be a git clone. " \
309 "The 'selfupdate' command cannot work in this case." 309 "The 'selfupdate' command cannot work in this case."
310 return 1 310 return 1
311 fi 311 fi
312 git pull 312 git pull
313 ) 313 )
314 } 314 }
315 315
316 antigen-cleanup () { 316 antigen-cleanup () {
317 317
318 # Cleanup unused repositories. 318 # Cleanup unused repositories.
319 319
320 local force=false 320 local force=false
321 if [[ $1 == --force ]]; then 321 if [[ $1 == --force ]]; then
322 force=true 322 force=true
323 fi 323 fi
324 324
325 if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then 325 if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then
326 echo "You don't have any bundles." 326 echo "You don't have any bundles."
327 return 0 327 return 0
328 fi 328 fi
329 329
330 # Find directores in ADOTDIR/repos, that are not in the bundles record. 330 # Find directores in ADOTDIR/repos, that are not in the bundles record.
331 local unused_clones="$(comm -13 \ 331 local unused_clones="$(comm -13 \
332 <(-antigen-echo-record | 332 <(-antigen-echo-record |
333 awk '$4 == "true" {print $1}' | 333 awk '$4 == "true" {print $1}' |
334 while read line; do 334 while read line; do
335 -antigen-get-clone-dir "$line" 335 -antigen-get-clone-dir "$line"
336 done | 336 done |
337 sort -u) \ 337 sort -u) \
338 <(ls -d "$ADOTDIR/repos/"* | sort -u))" 338 <(ls -d "$ADOTDIR/repos/"* | sort -u))"
339 339
340 if [[ -z $unused_clones ]]; then 340 if [[ -z $unused_clones ]]; then
341 echo "You don't have any unidentified bundles." 341 echo "You don't have any unidentified bundles."
342 return 0 342 return 0
343 fi 343 fi
344 344
345 echo 'You have clones for the following repos, but are not used.' 345 echo 'You have clones for the following repos, but are not used.'
346 echo "$unused_clones" | 346 echo "$unused_clones" |
347 while read line; do 347 while read line; do
348 -antigen-get-clone-url "$line" 348 -antigen-get-clone-url "$line"
349 done | 349 done |
350 sed -e 's/^/ /' -e 's/|/, branch /' 350 sed -e 's/^/ /' -e 's/|/, branch /'
351 351
352 if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then 352 if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then
353 echo 353 echo
354 echo 354 echo
355 echo "$unused_clones" | while read line; do 355 echo "$unused_clones" | while read line; do
356 echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." 356 echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..."
357 rm -rf "$line" 357 rm -rf "$line"
358 echo ' done.' 358 echo ' done.'
359 done 359 done
360 else 360 else
361 echo 361 echo
362 echo Nothing deleted. 362 echo Nothing deleted.
363 fi 363 fi
364 } 364 }
365 365
366 antigen-lib () { 366 antigen-lib () {
367 if [[ -z "$ZSH" ]]; then
368 export ZSH="$(-antigen-get-clone-dir "$ANTIGEN_DEFAULT_REPO_URL")"
369 fi
367 antigen-bundle --loc=lib 370 antigen-bundle --loc=lib
368 } 371 }
369 372
370 antigen-prezto-lib () { 373 antigen-prezto-lib () {
371 antigen-bundle sorin-ionescu/prezto 374 antigen-bundle sorin-ionescu/prezto
372 export ZDOTDIR=$ADOTDIR/repos/ 375 export ZDOTDIR=$ADOTDIR/repos/
373 } 376 }
374 377
375 antigen-theme () { 378 antigen-theme () {
376 379
377 if [[ "$1" != */* && "$1" != --* ]]; then 380 if [[ "$1" != */* && "$1" != --* ]]; then
378 # The first argument is just a name of the plugin, to be picked up from 381 # The first argument is just a name of the plugin, to be picked up from
379 # the default repo. 382 # the default repo.
380 local name="${1:-robbyrussell}" 383 local name="${1:-robbyrussell}"
381 antigen-bundle --loc=themes/$name --btype=theme 384 antigen-bundle --loc=themes/$name --btype=theme
382 385
383 else 386 else
384 antigen-bundle "$@" --btype=theme 387 antigen-bundle "$@" --btype=theme
385 388
386 fi 389 fi
387 390
388 } 391 }
389 392
390 antigen-apply () { 393 antigen-apply () {
391 # Initialize completion. 394 # Initialize completion.
392 # TODO: Only load completions if there are any changes to the bundle 395 # TODO: Only load completions if there are any changes to the bundle
393 # repositories. 396 # repositories.
394 compinit -i 397 compinit -i
395 } 398 }
396 399
397 antigen-list () { 400 antigen-list () {
398 # List all currently installed bundles. 401 # List all currently installed bundles.
399 if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then 402 if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then
400 echo "You don't have any bundles." >&2 403 echo "You don't have any bundles." >&2
401 return 1 404 return 1
402 else 405 else
403 -antigen-echo-record | sort -u 406 -antigen-echo-record | sort -u
404 fi 407 fi
405 } 408 }
406 409
407 antigen-snapshot () { 410 antigen-snapshot () {
408 411
409 local snapshot_file="${1:-antigen-shapshot}" 412 local snapshot_file="${1:-antigen-shapshot}"
410 413
411 # The snapshot content lines are pairs of repo-url and git version hash, in 414 # The snapshot content lines are pairs of repo-url and git version hash, in
412 # the form: 415 # the form:
413 # <version-hash> <repo-url> 416 # <version-hash> <repo-url>
414 local snapshot_content="$(-antigen-echo-record | 417 local snapshot_content="$(-antigen-echo-record |
415 grep 'true$' | 418 grep 'true$' |
416 sed 's/ .*$//' | 419 sed 's/ .*$//' |
417 sort -u | 420 sort -u |
418 while read url; do 421 while read url; do
419 local dir="$(-antigen-get-clone-dir "$url")" 422 local dir="$(-antigen-get-clone-dir "$url")"
420 local version_hash="$(cd "$dir" && git rev-parse HEAD)" 423 local version_hash="$(cd "$dir" && git rev-parse HEAD)"
421 echo "$version_hash $url" 424 echo "$version_hash $url"
422 done)" 425 done)"
423 426
424 { 427 {
425 # The first line in the snapshot file is for metadata, in the form: 428 # The first line in the snapshot file is for metadata, in the form:
426 # key='value'; key='value'; key='value'; 429 # key='value'; key='value'; key='value';
427 # Where `key`s are valid shell variable names. 430 # Where `key`s are valid shell variable names.
428 431
429 # Snapshot version. Has no relation to antigen version. If the snapshot 432 # Snapshot version. Has no relation to antigen version. If the snapshot
430 # file format changes, this number can be incremented. 433 # file format changes, this number can be incremented.
431 echo -n "version='1';" 434 echo -n "version='1';"
432 435
433 # Snapshot creation date+time. 436 # Snapshot creation date+time.
434 echo -n " created_on='$(date)';" 437 echo -n " created_on='$(date)';"
435 438
436 # Add a checksum with the md5 checksum of all the snapshot lines. 439 # Add a checksum with the md5 checksum of all the snapshot lines.
437 local checksum="$(echo "$snapshot_content" | md5sum)" 440 local checksum="$(echo "$snapshot_content" | md5sum)"
438 echo -n " checksum='${checksum%% *}';" 441 echo -n " checksum='${checksum%% *}';"
439 442
440 # A newline after the metadata and then the snapshot lines. 443 # A newline after the metadata and then the snapshot lines.
441 echo "\n$snapshot_content" 444 echo "\n$snapshot_content"
442 445
443 } > "$snapshot_file" 446 } > "$snapshot_file"
444 447
445 } 448 }
446 449
447 antigen-restore () { 450 antigen-restore () {
448 451
449 if [[ $# == 0 ]]; then 452 if [[ $# == 0 ]]; then
450 echo 'Please provide a snapshot file to restore from.' >&2 453 echo 'Please provide a snapshot file to restore from.' >&2
451 return 1 454 return 1
452 fi 455 fi
453 456
454 local snapshot_file="$1" 457 local snapshot_file="$1"
455 458
456 # TODO: Before doing anything with the snapshot file, verify its checksum. 459 # TODO: Before doing anything with the snapshot file, verify its checksum.
457 # If it fails, notify this to the user and confirm if restore should 460 # If it fails, notify this to the user and confirm if restore should
458 # proceed. 461 # proceed.
459 462
460 echo -n "Restoring from $snapshot_file..." 463 echo -n "Restoring from $snapshot_file..."
461 464
462 sed -n '1!p' "$snapshot_file" | 465 sed -n '1!p' "$snapshot_file" |
463 while read line; do 466 while read line; do
464 467
465 local version_hash="${line%% *}" 468 local version_hash="${line%% *}"
466 local url="${line##* }" 469 local url="${line##* }"
467 local clone_dir="$(-antigen-get-clone-dir "$url")" 470 local clone_dir="$(-antigen-get-clone-dir "$url")"
468 471
469 if [[ ! -d $clone_dir ]]; then 472 if [[ ! -d $clone_dir ]]; then
470 git clone "$url" "$clone_dir" > /dev/null 473 git clone "$url" "$clone_dir" > /dev/null
471 fi 474 fi
472 475
473 (cd "$clone_dir" && git checkout $version_hash) 2> /dev/null 476 (cd "$clone_dir" && git checkout $version_hash) 2> /dev/null
474 477
475 done 478 done
476 479
477 echo ' done.' 480 echo ' done.'
478 echo 'Please open a new shell to get the restored changes.' 481 echo 'Please open a new shell to get the restored changes.'
479 } 482 }
480 483
481 antigen-help () { 484 antigen-help () {
482 cat <<EOF 485 cat <<EOF
483 Antigen is a plugin management system for zsh. It makes it easy to grab awesome 486 Antigen is a plugin management system for zsh. It makes it easy to grab awesome
484 shell scripts and utilities, put up on github. For further details and complete 487 shell scripts and utilities, put up on github. For further details and complete
485 documentation, visit the project's page at 'http://antigen.sharats.me'. 488 documentation, visit the project's page at 'http://antigen.sharats.me'.
486 EOF 489 EOF
487 } 490 }
488 491
489 # A syntax sugar to avoid the `-` when calling antigen commands. With this 492 # A syntax sugar to avoid the `-` when calling antigen commands. With this
490 # function, you can write `antigen-bundle` as `antigen bundle` and so on. 493 # function, you can write `antigen-bundle` as `antigen bundle` and so on.
491 antigen () { 494 antigen () {
492 local cmd="$1" 495 local cmd="$1"
493 shift 496 shift
494 "antigen-$cmd" "$@" 497 "antigen-$cmd" "$@"
495 } 498 }
496 499
497 -antigen-parse-args () { 500 -antigen-parse-args () {
498 # An argument parsing functionality to parse arguments the *antigen* way :). 501 # An argument parsing functionality to parse arguments the *antigen* way :).
499 # Takes one first argument (called spec), which dictates how to parse and 502 # Takes one first argument (called spec), which dictates how to parse and
500 # the rest of the arguments are parsed. Outputs a piece of valid shell code 503 # the rest of the arguments are parsed. Outputs a piece of valid shell code
501 # that can be passed to `eval` inside a function which creates the arguments 504 # that can be passed to `eval` inside a function which creates the arguments
502 # and their values as local variables. Suggested use is to set the defaults 505 # and their values as local variables. Suggested use is to set the defaults
503 # to all arguments first and then eval the output of this function. 506 # to all arguments first and then eval the output of this function.
504 507
505 # Spec: Only long argument supported. No support for parsing short options. 508 # Spec: Only long argument supported. No support for parsing short options.
506 # The spec must have two sections, separated by a `;`. 509 # The spec must have two sections, separated by a `;`.
507 # '<positional-arguments>;<keyword-only-arguments>' 510 # '<positional-arguments>;<keyword-only-arguments>'
508 # Positional arguments are passed as just values, like `command a b`. 511 # Positional arguments are passed as just values, like `command a b`.
509 # Keyword arguments are passed as a `--name=value` pair, like `command 512 # Keyword arguments are passed as a `--name=value` pair, like `command
510 # --arg1=a --arg2=b`. 513 # --arg1=a --arg2=b`.
511 514
512 # Each argument in the spec is separated by a `,`. Each keyword argument can 515 # Each argument in the spec is separated by a `,`. Each keyword argument can
513 # end in a `:` to specifiy that this argument wants a value, otherwise it 516 # end in a `:` to specifiy that this argument wants a value, otherwise it
514 # doesn't take a value. (The value in the output when the keyword argument 517 # doesn't take a value. (The value in the output when the keyword argument
515 # doesn't have a `:` is `true`). 518 # doesn't have a `:` is `true`).
516 519
517 # Arguments in either section can end with a `?` (should come after `:`, if 520 # Arguments in either section can end with a `?` (should come after `:`, if
518 # both are present), means optional. FIXME: Not yet implemented. 521 # both are present), means optional. FIXME: Not yet implemented.
519 522
520 # See the test file, tests/arg-parser.t for (working) examples. 523 # See the test file, tests/arg-parser.t for (working) examples.
521 524
522 local spec="$1" 525 local spec="$1"
523 shift 526 shift
524 527
525 # Sanitize the spec 528 # Sanitize the spec
526 spec="$(echo "$spec" | tr '\n' ' ' | sed 's/[[:space:]]//g')" 529 spec="$(echo "$spec" | tr '\n' ' ' | sed 's/[[:space:]]//g')"
527 530
528 local code='' 531 local code=''
529 532
530 --add-var () { 533 --add-var () {
531 test -z "$code" || code="$code\n" 534 test -z "$code" || code="$code\n"
532 code="${code}local $1='$2'" 535 code="${code}local $1='$2'"
533 } 536 }
534 537
535 local positional_args="$(echo "$spec" | cut -d\; -f1)" 538 local positional_args="$(echo "$spec" | cut -d\; -f1)"
536 local positional_args_count="$(echo $positional_args | 539 local positional_args_count="$(echo $positional_args |
537 awk -F, '{print NF}')" 540 awk -F, '{print NF}')"
538 541
539 # Set spec values based on the positional arguments. 542 # Set spec values based on the positional arguments.
540 local i=1 543 local i=1
541 while ! [[ -z $1 || $1 == --* ]]; do 544 while ! [[ -z $1 || $1 == --* ]]; do
542 545
543 if (( $i > $positional_args_count )); then 546 if (( $i > $positional_args_count )); then
544 echo "Only $positional_args_count positional arguments allowed." >&2 547 echo "Only $positional_args_count positional arguments allowed." >&2
545 echo "Found at least one more: '$1'" >&2 548 echo "Found at least one more: '$1'" >&2
546 return 549 return
547 fi 550 fi
548 551
549 local name_spec="$(echo "$positional_args" | cut -d, -f$i)" 552 local name_spec="$(echo "$positional_args" | cut -d, -f$i)"
550 local name="${${name_spec%\?}%:}" 553 local name="${${name_spec%\?}%:}"
551 local value="$1" 554 local value="$1"
552 555
553 if echo "$code" | grep -qm1 "^local $name="; then 556 if echo "$code" | grep -qm1 "^local $name="; then
554 echo "Argument '$name' repeated with the value '$value'". >&2 557 echo "Argument '$name' repeated with the value '$value'". >&2
555 return 558 return
556 fi 559 fi
557 560
558 --add-var $name "$value" 561 --add-var $name "$value"
559 562
560 shift 563 shift
561 i=$(($i + 1)) 564 i=$(($i + 1))
562 done 565 done
563 566
564 local keyword_args="$( 567 local keyword_args="$(
565 # Positional arguments can double up as keyword arguments too. 568 # Positional arguments can double up as keyword arguments too.
566 echo "$positional_args" | tr , '\n' | 569 echo "$positional_args" | tr , '\n' |
567 while read line; do 570 while read line; do
568 if [[ $line == *\? ]]; then 571 if [[ $line == *\? ]]; then
569 echo "${line%?}:?" 572 echo "${line%?}:?"
570 else 573 else
571 echo "$line:" 574 echo "$line:"
572 fi 575 fi
573 done 576 done
574 577
575 # Specified keyword arguments. 578 # Specified keyword arguments.
576 echo "$spec" | cut -d\; -f2 | tr , '\n' 579 echo "$spec" | cut -d\; -f2 | tr , '\n'
577 )" 580 )"
578 local keyword_args_count="$(echo $keyword_args | awk -F, '{print NF}')" 581 local keyword_args_count="$(echo $keyword_args | awk -F, '{print NF}')"
579 582
580 # Set spec values from keyword arguments, if any. The remaining arguments 583 # Set spec values from keyword arguments, if any. The remaining arguments
581 # are all assumed to be keyword arguments. 584 # are all assumed to be keyword arguments.
582 while [[ $1 == --* ]]; do 585 while [[ $1 == --* ]]; do
583 # Remove the `--` at the start. 586 # Remove the `--` at the start.
584 local arg="${1#--}" 587 local arg="${1#--}"
585 588
586 # Get the argument name and value. 589 # Get the argument name and value.
587 if [[ $arg != *=* ]]; then 590 if [[ $arg != *=* ]]; then
588 local name="$arg" 591 local name="$arg"
589 local value='' 592 local value=''
590 else 593 else
591 local name="${arg%\=*}" 594 local name="${arg%\=*}"
592 local value="${arg#*=}" 595 local value="${arg#*=}"
593 fi 596 fi
594 597
595 if echo "$code" | grep -qm1 "^local $name="; then 598 if echo "$code" | grep -qm1 "^local $name="; then
596 echo "Argument '$name' repeated with the value '$value'". >&2 599 echo "Argument '$name' repeated with the value '$value'". >&2
597 return 600 return
598 fi 601 fi
599 602
600 # The specification for this argument, used for validations. 603 # The specification for this argument, used for validations.
601 local arg_line="$(echo "$keyword_args" | grep -m1 "^$name:\??\?")" 604 local arg_line="$(echo "$keyword_args" | grep -m1 "^$name:\??\?")"
602 605
603 # Validate argument and value. 606 # Validate argument and value.
604 if [[ -z $arg_line ]]; then 607 if [[ -z $arg_line ]]; then
605 # This argument is not known to us. 608 # This argument is not known to us.
606 echo "Unknown argument '$name'." >&2 609 echo "Unknown argument '$name'." >&2
607 return 610 return
608 611
609 elif (echo "$arg_line" | grep -qm1 ':') && [[ -z $value ]]; then 612 elif (echo "$arg_line" | grep -qm1 ':') && [[ -z $value ]]; then
610 # This argument needs a value, but is not provided. 613 # This argument needs a value, but is not provided.
611 echo "Required argument for '$name' not provided." >&2 614 echo "Required argument for '$name' not provided." >&2
612 return 615 return
613 616
614 elif (echo "$arg_line" | grep -vqm1 ':') && [[ ! -z $value ]]; then 617 elif (echo "$arg_line" | grep -vqm1 ':') && [[ ! -z $value ]]; then
615 # This argument doesn't need a value, but is provided. 618 # This argument doesn't need a value, but is provided.
616 echo "No argument required for '$name', but provided '$value'." >&2 619 echo "No argument required for '$name', but provided '$value'." >&2
617 return 620 return
618 621
619 fi 622 fi
620 623
621 if [[ -z $value ]]; then 624 if [[ -z $value ]]; then
622 value=true 625 value=true
623 fi 626 fi
624 627
625 --add-var "${name//-/_}" "$value" 628 --add-var "${name//-/_}" "$value"
626 shift 629 shift
627 done 630 done
628 631
629 echo "$code" 632 echo "$code"
630 633
631 unfunction -- --add-var 634 unfunction -- --add-var
632 635
633 } 636 }
634 637
635 # Echo the bundle specs as in the record. The first line is not echoed since it 638 # Echo the bundle specs as in the record. The first line is not echoed since it
636 # is a blank line. 639 # is a blank line.
637 -antigen-echo-record () { 640 -antigen-echo-record () {
638 echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' 641 echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p'
639 } 642 }
640 643
641 -antigen-env-setup () { 644 -antigen-env-setup () {
642 645
643 # Helper function: Same as `export $1=$2`, but will only happen if the name 646 # Helper function: Same as `export $1=$2`, but will only happen if the name
644 # specified by `$1` is not already set. 647 # specified by `$1` is not already set.
645 -set-default () { 648 -set-default () {
646 local arg_name="$1" 649 local arg_name="$1"
647 local arg_value="$2" 650 local arg_value="$2"
648 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" 651 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'"
649 } 652 }
650 653
651 # Pre-startup initializations. 654 # Pre-startup initializations.
652 -set-default ANTIGEN_DEFAULT_REPO_URL \ 655 -set-default ANTIGEN_DEFAULT_REPO_URL \
653 https://github.com/robbyrussell/oh-my-zsh.git 656 https://github.com/robbyrussell/oh-my-zsh.git
654 -set-default ADOTDIR $HOME/.antigen 657 -set-default ADOTDIR $HOME/.antigen
655 658
656 # Load the compinit module. Required for `compdef` to be defined, which is 659 # Load the compinit module. Required for `compdef` to be defined, which is
657 # used by many plugins to define completions. 660 # used by many plugins to define completions.
658 autoload -U compinit 661 autoload -U compinit
659 compinit -i 662 compinit -i
660 663
661 # Setup antigen's own completion. 664 # Setup antigen's own completion.
662 compdef _antigen antigen 665 compdef _antigen antigen
663 666
664 # Remove private functions. 667 # Remove private functions.
665 unfunction -- -set-default 668 unfunction -- -set-default
666 } 669 }
667 670
668 # Setup antigen's autocompletion 671 # Setup antigen's autocompletion
669 _antigen () { 672 _antigen () {
670 compadd \ 673 compadd \
671 bundle \ 674 bundle \
672 bundles \ 675 bundles \
673 update \ 676 update \
674 revert \ 677 revert \
675 list \ 678 list \
676 cleanup \ 679 cleanup \
677 lib \ 680 lib \
678 selfupdate \ 681 selfupdate \
679 theme \ 682 theme \
680 apply \ 683 apply \
681 help 684 help
682 } 685 }
683 686
684 -antigen-env-setup 687 -antigen-env-setup
685 688