Commit da678afb28803f7ed292ec13a43aeb818a510053

Authored by Adam Stankiewicz
1 parent 23ddf43369

Introduce antigen-use command

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