Commit e6cc15b5f558ba66c1aa44af4f557c8140c8234e

Authored by Shrikant Sharat
1 parent c46b6673e4

Fix local paths with branches not working.

Local bundles, if are recorded with a `--branch` option, should *always* be
cloned.

Showing 2 changed files with 12 additions and 7 deletions Inline Diff

1 # Antigen 1 # Antigen
2 2
3 Antigen is a small set of functions that help you easily manage your shell (zsh) 3 Antigen is a small set of functions that help you easily manage your shell (zsh)
4 plugins, called bundles. The concept is pretty much the same as bundles in a 4 plugins, called bundles. The concept is pretty much the same as bundles in a
5 typical vim+pathogen setup. Antigen is to zsh, what [Vundle][] is to vim. 5 typical vim+pathogen setup. Antigen is to zsh, what [Vundle][] is to vim.
6 6
7 Please note that this is a very new project and can be considered beta at best. 7 Please note that this is a very new project and can be considered beta at best.
8 That said, I am using antigen full time now on my work machine. Also, please 8 That said, I am using antigen full time now on my work machine. Also, please
9 read the commit comments of the changesets when you pull a new version of 9 read the commit comments of the changesets when you pull a new version of
10 antigen. 10 antigen.
11 11
12 ## Show off 12 ## Show off
13 13
14 > Enough talk. Let's fight! 14 > Enough talk. Let's fight!
15 > -- Po, Kung-fu Panda. 15 > -- Po, Kung-fu Panda.
16 16
17 You're going to experience antigen right in your open shell. No `.zshrc` 17 You're going to experience antigen right in your open shell. No `.zshrc`
18 tweaking and reading the rest of this documentation. Kinda like an ice-cream 18 tweaking and reading the rest of this documentation. Kinda like an ice-cream
19 sample, if you will. 19 sample, if you will.
20 20
21 Get and load antigen. 21 Get and load antigen.
22 22
23 curl https://raw.github.com/zsh-users/antigen/master/antigen.zsh > antigen.zsh 23 curl https://raw.github.com/zsh-users/antigen/master/antigen.zsh > antigen.zsh
24 source antigen.zsh 24 source antigen.zsh
25 25
26 There. You now have all the antigen goodies. Let's try install some plugins. How 26 There. You now have all the antigen goodies. Let's try install some plugins. How
27 about some color to start with. Get the [syntax highlighting plugin][] by 27 about some color to start with. Get the [syntax highlighting plugin][] by
28 running 28 running
29 29
30 antigen-bundle zsh-users/zsh-syntax-highlighting 30 antigen-bundle zsh-users/zsh-syntax-highlighting
31 31
32 Now let it do its thing and once its done and you're back at your prompt, try 32 Now let it do its thing and once its done and you're back at your prompt, try
33 and type a command. See that? Colors! 33 and type a command. See that? Colors!
34 34
35 So, you do git? ruby? git and ruby? There are lots of awesome plugins over at 35 So, you do git? ruby? git and ruby? There are lots of awesome plugins over at
36 oh-my-zsh. Treat yourself to some. 36 oh-my-zsh. Treat yourself to some.
37 37
38 antigen-bundle robbyrussell/oh-my-zsh plugins/ruby 38 antigen-bundle robbyrussell/oh-my-zsh plugins/ruby
39 antigen-bundle robbyrussell/oh-my-zsh plugins/git 39 antigen-bundle robbyrussell/oh-my-zsh plugins/git
40 40
41 There are lots of plugins out there in the wild and people are writing zsh 41 There are lots of plugins out there in the wild and people are writing zsh
42 utilities as small scripts all the time. Antigen is compatible with all of them. 42 utilities as small scripts all the time. Antigen is compatible with all of them.
43 The plugins and scripts don't need any special handling to be compatible with 43 The plugins and scripts don't need any special handling to be compatible with
44 antigen. 44 antigen.
45 45
46 Another example, [kennethreitz's autoenv](autoenv). Just a bundle command away. 46 Another example, [kennethreitz's autoenv](autoenv). Just a bundle command away.
47 47
48 antigen-bundle kennethreitz/autoenv 48 antigen-bundle kennethreitz/autoenv
49 49
50 And boom! you have all the autoenv goodness. Just remember how you used to do 50 And boom! you have all the autoenv goodness. Just remember how you used to do
51 these before antigen, clone it, modify your bashrc to source it, load a new 51 these before antigen, clone it, modify your bashrc to source it, load a new
52 terminal, all just to test it out. Duh! 52 terminal, all just to test it out. Duh!
53 53
54 The side effect of this is that you can tell antigen to grab just about anything 54 The side effect of this is that you can tell antigen to grab just about anything
55 from anyone's `dotfiles` repo, as long as it is in a directory under any repo on 55 from anyone's `dotfiles` repo, as long as it is in a directory under any repo on
56 github. 56 github.
57 57
58 And themes? How would you like a fancy new prompt for yourself? 58 And themes? How would you like a fancy new prompt for yourself?
59 59
60 antigen-theme funky 60 antigen-theme funky
61 61
62 No? Not your taste? There are many themes available to you, check out the 62 No? Not your taste? There are many themes available to you, check out the
63 oh-my-zsh's [page on themes][]. (You can currently only install themes from 63 oh-my-zsh's [page on themes][]. (You can currently only install themes from
64 robbyrussell's, i.e., the canonical oh-my-zsh repo). 64 robbyrussell's, i.e., the canonical oh-my-zsh repo).
65 65
66 Note: Many of those plugins and especially themes, assume you have the core 66 Note: Many of those plugins and especially themes, assume you have the core
67 library of oh-my-zsh loaded. So, if you want to experiment further, issue a 67 library of oh-my-zsh loaded. So, if you want to experiment further, issue a
68 68
69 antigen-lib 69 antigen-lib
70 70
71 and continue until you're tired. At which point you can come back to this page 71 and continue until you're tired. At which point you can come back to this page
72 ;) 72 ;)
73 73
74 ## Usage 74 ## Usage
75 75
76 So, now that you're here, I'll assume you are convinced and want antigen running 76 So, now that you're here, I'll assume you are convinced and want antigen running
77 your shell all the time. Sweet. Let's do it. 77 your shell all the time. Sweet. Let's do it.
78 78
79 First, clone this repo, probably as a submodule if you have your dotfiles in a 79 First, clone this repo, probably as a submodule if you have your dotfiles in a
80 git repo, 80 git repo,
81 81
82 git clone https://github.com/sharat87/antigen.git 82 git clone https://github.com/sharat87/antigen.git
83 83
84 The usage should be very familiar to you if you use Vundle. A typical `.zshrc` 84 The usage should be very familiar to you if you use Vundle. A typical `.zshrc`
85 might look like this 85 might look like this
86 86
87 source /path-to-antigen-clone/antigen.zsh 87 source /path-to-antigen-clone/antigen.zsh
88 88
89 # Load the oh-my-zsh's library. 89 # Load the oh-my-zsh's library.
90 antigen-lib 90 antigen-lib
91 91
92 # Bundles from the default repo (robbyrussell's oh-my-zsh). 92 # Bundles from the default repo (robbyrussell's oh-my-zsh).
93 antigen-bundle git 93 antigen-bundle git
94 antigen-bundle heroku 94 antigen-bundle heroku
95 antigen-bundle pip 95 antigen-bundle pip
96 antigen-bundle lein 96 antigen-bundle lein
97 antigen-bundle command-not-found 97 antigen-bundle command-not-found
98 98
99 # Syntax highlighting bundle. 99 # Syntax highlighting bundle.
100 antigen-bundle zsh-users/zsh-syntax-highlighting 100 antigen-bundle zsh-users/zsh-syntax-highlighting
101 101
102 # Load the theme. 102 # Load the theme.
103 antigen-theme robbyrussell 103 antigen-theme robbyrussell
104 104
105 # Tell antigen that you're done. 105 # Tell antigen that you're done.
106 antigen-apply 106 antigen-apply
107 107
108 Open your zsh with this zshrc and you should see all the bundles you defined 108 Open your zsh with this zshrc and you should see all the bundles you defined
109 here, getting installed. Once its done, you are ready to roll. The complete 109 here, getting installed. Once its done, you are ready to roll. The complete
110 syntax for the `antigen-bundle` command is discussed further down on this page. 110 syntax for the `antigen-bundle` command is discussed further down on this page.
111 111
112 ## Motivation 112 ## Motivation
113 113
114 If you use zsh and [oh-my-zsh][], you know that having many different plugins 114 If you use zsh and [oh-my-zsh][], you know that having many different plugins
115 that are developed by many different authors in a single (sub)repo is not a very 115 that are developed by many different authors in a single (sub)repo is not a very
116 easy to maintain. There are some really fantastic plugins and utilities in 116 easy to maintain. There are some really fantastic plugins and utilities in
117 oh-my-zsh, but having them all in a single repo doesn't really scale well. And I 117 oh-my-zsh, but having them all in a single repo doesn't really scale well. And I
118 admire robbyrussell's efforts for reviewing and merging the gigantic number of 118 admire robbyrussell's efforts for reviewing and merging the gigantic number of
119 pull requests the project gets. It needs a better way of plugin management. 119 pull requests the project gets. It needs a better way of plugin management.
120 120
121 This was discussed on [a][1] [few][2] [issues][3], but it doesn't look like 121 This was discussed on [a][1] [few][2] [issues][3], but it doesn't look like
122 there was any progress made. So, I'm trying to start this off with antigen, 122 there was any progress made. So, I'm trying to start this off with antigen,
123 hoping to better this situation. Please note that I'm by no means a zsh or any 123 hoping to better this situation. Please note that I'm by no means a zsh or any
124 shell script expert (far from it). 124 shell script expert (far from it).
125 125
126 [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465 126 [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465
127 [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377 127 [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377
128 [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014 128 [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014
129 129
130 Inspired by vundle, antigen can pull oh-my-zsh style plugins from various github 130 Inspired by vundle, antigen can pull oh-my-zsh style plugins from various github
131 repositories. You are not limited to use plugins from the oh-my-zsh repository 131 repositories. You are not limited to use plugins from the oh-my-zsh repository
132 only and you don't need to maintain your own fork and pull from upstream every 132 only and you don't need to maintain your own fork and pull from upstream every
133 now and then. 133 now and then.
134 134
135 Antigen also lets you switch the prompt theme with one command, just like that 135 Antigen also lets you switch the prompt theme with one command, just like that
136 136
137 bundle-theme candy 137 bundle-theme candy
138 138
139 and your prompt is changed, just for this session of course. 139 and your prompt is changed, just for this session of course.
140 140
141 ## Commands 141 ## Commands
142 142
143 The following are the commands provided by antigen. Note that the `-` in the 143 The following are the commands provided by antigen. Note that the `-` in the
144 following commands is kind of optional. You can write `antigen-bundle ...` as 144 following commands is kind of optional. You can write `antigen-bundle ...` as
145 `antigen bundle` and get away with it. For more details see the help on 145 `antigen bundle` and get away with it. For more details see the help on
146 `antigen` command further down in this section. 146 `antigen` command further down in this section.
147 147
148 ### antigen-bundle 148 ### antigen-bundle
149 149
150 This command tells antigen to install (if not already installed) and load the 150 This command tells antigen to install (if not already installed) and load the
151 given plugin. The simplest usage follows the following syntax. 151 given plugin. The simplest usage follows the following syntax.
152 152
153 antigen-bundle <plugin-name> 153 antigen-bundle <plugin-name>
154 154
155 This will install the `plugins/<name>` directory from [robbyrussell's 155 This will install the `plugins/<name>` directory from [robbyrussell's
156 oh-my-zsh][oh-my-zsh] (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`). 156 oh-my-zsh][oh-my-zsh] (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`).
157 157
158 However, the above is just syntax sugar for the extended syntax of the 158 However, the above is just syntax sugar for the extended syntax of the
159 `antigen-bundle` command. 159 `antigen-bundle` command.
160 160
161 antigen-bundle [<url> [<loc>]] 161 antigen-bundle [<url> [<loc>]]
162 162
163 where `<url>` is the repository url and it defaults to [robbyrussell's 163 where `<url>` is the repository url and it defaults to [robbyrussell's
164 oh-my-zsh][oh-my-zsh] repo (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL` 164 oh-my-zsh][oh-my-zsh] repo (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`
165 discussed further down). `<loc>` is the path under this repository which has the 165 discussed further down). `<loc>` is the path under this repository which has the
166 zsh plugin. This is typically the directory that contains a `*.plugin.zsh` file, 166 zsh plugin. This is typically the directory that contains a `*.plugin.zsh` file,
167 but it could contain a completion file or just many `*.zsh` files to be sourced. 167 but it could contain a completion file or just many `*.zsh` files to be sourced.
168 `<loc>` defaults to `/`, which indicates the repository itself is a plugin. 168 `<loc>` defaults to `/`, which indicates the repository itself is a plugin.
169 169
170 An example invocation would be 170 An example invocation would be
171 171
172 # The following is the same as `antigen-bundle ant`. But for demonstration 172 # The following is the same as `antigen-bundle ant`. But for demonstration
173 # purposes, we use the extended syntax here. 173 # purposes, we use the extended syntax here.
174 antigen-bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant 174 antigen-bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant
175 175
176 This would install the ant plugin from robbyrussell's oh-my-zsh repo. Of course, 176 This would install the ant plugin from robbyrussell's oh-my-zsh repo. Of course,
177 github url's can be shortened. 177 github url's can be shortened.
178 178
179 antigen-bundle robbyrussell/oh-my-zsh plugins/ant 179 antigen-bundle robbyrussell/oh-my-zsh plugins/ant
180 180
181 And since this repo is the default, even that isn't necessary. But we can't 181 And since this repo is the default, even that isn't necessary. But we can't
182 specify the `loc` without giving the first argument. 182 specify the `loc` without giving the first argument.
183 183
184 For this and a few other reasons, `antigen-bundle` also supports a simple 184 For this and a few other reasons, `antigen-bundle` also supports a simple
185 keyword argument syntax, using which we can rewrite the above as 185 keyword argument syntax, using which we can rewrite the above as
186 186
187 antigen-bundle --loc=plugins/ant 187 antigen-bundle --loc=plugins/ant
188 188
189 Which picks up the default for the `url` argument, and uses the `loc` given to 189 Which picks up the default for the `url` argument, and uses the `loc` given to
190 it. 190 it.
191 191
192 *Note* that you can mix and match positional and keyword arguments. But you 192 *Note* that you can mix and match positional and keyword arguments. But you
193 can't have positional arguments after keyword arguments. 193 can't have positional arguments after keyword arguments.
194 194
195 antigen-bundle robbyrussell/oh-my-zsh --loc=plugins/ant 195 antigen-bundle robbyrussell/oh-my-zsh --loc=plugins/ant
196 196
197 And keyword arguments don't care about the order in which the arguments are 197 And keyword arguments don't care about the order in which the arguments are
198 specified. The following is perfectly valid. 198 specified. The following is perfectly valid.
199 199
200 antigen-bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh 200 antigen-bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh
201 201
202 You can also specify a local directory on your file system as a bundle. In this 202 You can also specify a local directory on your file system as a bundle. In this
203 case, make sure the path you give is the absolute path (i.e., starts with a 203 case, make sure the path you give is the absolute path (i.e., starts with a
204 `/`). Relative paths are not supported. If the repo you gave is a local 204 `/`). Relative paths are not supported. If the repo you gave is a local
205 directory path, then it is not necessary that this path is a git repo. Please 205 directory path, then it is not necessary that this path is a git repo. Please
206 refer to the notes on `--no-local-repo` below. 206 refer to the notes on `--no-local-clone` below.
207 207
208 In addition to the above discussed arguments, `antigen-bundle` also takes a 208 In addition to the above discussed arguments, `antigen-bundle` also takes a
209 `btype` keyword-only argument, that is used internally. You shouldn't be 209 `btype` keyword-only argument, that is used internally. You shouldn't be
210 concerned with this argument, its only used internally and will probably go away 210 concerned with this argument, its only used internally and will probably go away
211 in the future. It indicates whether the bundle is a theme or a simple plugin. 211 in the future. It indicates whether the bundle is a theme or a simple plugin.
212 212
213 You can use this `antigen-bundle` command not just from your `.zshrc`, but also 213 You can use this `antigen-bundle` command not just from your `.zshrc`, but also
214 from your shell environment. This allows you to install plugins on the fly and 214 from your shell environment. This allows you to install plugins on the fly and
215 try them out. Of course if you want a bundle to be available every time you open 215 try them out. Of course if you want a bundle to be available every time you open
216 a shell, put it in your `.zshrc`. 216 a shell, put it in your `.zshrc`.
217 217
218 Other keyword-only arguments accepted: 218 Other keyword-only arguments accepted:
219 219
220 `--branch={git-branch-name}` &mdash; Specify the branch of the git repo to be 220 `--branch={git-branch-name}` &mdash; Specify the branch of the git repo to be
221 used for this bundle (without the braces of course). The default is whatever 221 used for this bundle (without the braces of course). The default is whatever
222 branch the clone comes with, which is usually `master`. For example, 222 branch the clone comes with, which is usually `master`. For example,
223 223
224 antigen-bundle github-user/repo --branch=develop 224 antigen-bundle github-user/repo --branch=develop
225 225
226 This will get the plugin as in the branch `develop`. 226 This will get the plugin as in the branch `develop`.
227 227
228 Note that if you specify two plugins to be loaded from the same git repo, but 228 Note that if you specify two plugins to be loaded from the same git repo, but
229 different branches, then two separate clones of this repo will be maintained. 229 different branches, then two separate clones of this repo will be maintained.
230 This is a small implementation detail and shouldn't influence you in any way. 230 This is a small implementation detail and shouldn't influence you in any way.
231 231
232 `--no-local-clone` &mdash; This command can be useful if you are developing a 232 `--no-local-clone` &mdash; This command can be useful if you are developing a
233 plugin and already have a clone on your local file system. If this argument is 233 plugin and already have a clone on your local file system. If this argument is
234 not given, even if the given repo url is a local path, a clone is made in the 234 not given, even if the given repo url is a local path, a clone is made in the
235 `$ADOTDIR/repos`, and the plugin is loaded from that clone. But, if you give 235 `$ADOTDIR/repos`, and the plugin is loaded from that clone. But, if you give
236 this argument, the plugin is sourced straight from the repo location, without 236 this argument, the plugin is sourced straight from the repo location, without
237 creating a clone. For example, 237 creating a clone. For example,
238 238
239 antigen-bundle /absolute/path/to/the/plugin --no-local-clone 239 antigen-bundle /absolute/path/to/the/plugin --no-local-clone
240 240
241 Note that if the repo url is *not* an absolute local path, this argument has no 241 Note that if the repo url is *not* an absolute local path or a branch has been
242 effect. 242 specified with the `--branch` option, this argument has no effect. That is,
243 for this option to have any affect, the repo url must be an absolute local path
244 and no `--branch` should be specified.
243 245
244 Also, if the local path given as the url is not a git repo, then this 246 Also, if the local path given as the url is not a git repo, then this
245 argument is forced as it doesn't makes sense to *clone* something that's not a 247 argument is forced as it doesn't makes sense to *clone* something that's not a
246 git repo. This property can be used to load any utility scripts you have in your 248 git repo. This property can be used to load any utility scripts you have in your
247 dotfiles repo. For example, 249 dotfiles repo. For example,
248 250
249 antigen-bundle $HOME/dotfiles/oh-my-zsh/custom 251 antigen-bundle $HOME/dotfiles/oh-my-zsh/custom
250 252
251 ### antigen-bundles 253 ### antigen-bundles
252 254
253 If you have a fair number of bundles, using the `antigen-bundle` command can 255 If you have a fair number of bundles, using the `antigen-bundle` command can
254 look cumbersome. You can use the `antigen-bundles` command to *bulk* define 256 look cumbersome. You can use the `antigen-bundles` command to *bulk* define
255 bundles instead of individual calls to `antigen-bundle`. 257 bundles instead of individual calls to `antigen-bundle`.
256 258
257 Usage is pretty straightforward. Just pipe the bundle specifications, just as 259 Usage is pretty straightforward. Just pipe the bundle specifications, just as
258 you would give to the `antigen-bundle` command, one per line, into the 260 you would give to the `antigen-bundle` command, one per line, into the
259 `antigen-bundles` command. The easiest way to do this, is using the heredoc 261 `antigen-bundles` command. The easiest way to do this, is using the heredoc
260 syntax. 262 syntax.
261 263
262 antigen-bundles <<EOF 264 antigen-bundles <<EOF
263 # Guess what to install when running an unknown command. 265 # Guess what to install when running an unknown command.
264 command-not-found 266 command-not-found
265 267
266 # The heroku tool helper plugin. 268 # The heroku tool helper plugin.
267 heroku 269 heroku
268 270
269 EOF 271 EOF
270 272
271 This is equivalent to 273 This is equivalent to
272 274
273 antigen-bundle command-not-found 275 antigen-bundle command-not-found
274 antigen-bundle heroku 276 antigen-bundle heroku
275 277
276 Of course, as you can see, from the lines piped to `antigen-bundles`, empty 278 Of course, as you can see, from the lines piped to `antigen-bundles`, empty
277 lines and those starting with a `#` are ignored. The rest are passed to 279 lines and those starting with a `#` are ignored. The rest are passed to
278 `antigen-bundle` without any quoting rules applied. They are actually `eval`-ed 280 `antigen-bundle` without any quoting rules applied. They are actually `eval`-ed
279 with the `antigen-bundle` command. See the source if you want to really 281 with the `antigen-bundle` command. See the source if you want to really
280 understand how it works. Its a very small function. 282 understand how it works. Its a very small function.
281 283
282 ### antigen-update 284 ### antigen-update
283 285
284 This is something you might not want to put in your `.zshrc`. Instead, run it 286 This is something you might not want to put in your `.zshrc`. Instead, run it
285 occasionally to update all your plugins. It doesn't take any arguments. 287 occasionally to update all your plugins. It doesn't take any arguments.
286 288
287 antigen-update 289 antigen-update
288 290
289 Please note that the updates that are downloaded are not immediately available. 291 Please note that the updates that are downloaded are not immediately available.
290 You have to open a new shell to be able to see the changes. This is a limitation 292 You have to open a new shell to be able to see the changes. This is a limitation
291 by design since reloading all the plugins *might* have some nasty side effects 293 by design since reloading all the plugins *might* have some nasty side effects
292 that may not be immediately apparent. Let's just say it can make your shell act 294 that may not be immediately apparent. Let's just say it can make your shell act
293 real quirky. 295 real quirky.
294 296
295 **Please note**: This command is not for updating *antigen* itself. Its for 297 **Please note**: This command is not for updating *antigen* itself. Its for
296 updating the bundles you are using with antigen. 298 updating the bundles you are using with antigen.
297 299
298 ### antigen-list 300 ### antigen-list
299 301
300 Use this command to list out the currently *loaded* plugins. Keep in mind that 302 Use this command to list out the currently *loaded* plugins. Keep in mind that
301 this includes any bundles installed on-the-fly. 303 this includes any bundles installed on-the-fly.
302 304
303 Takes no arguments. Gives out the repo url and the plugin's location under the 305 Takes no arguments. Gives out the repo url and the plugin's location under the
304 repo. 306 repo.
305 307
306 ### antigen-cleanup 308 ### antigen-cleanup
307 309
308 Used to clean up the clones of repos which are not used by any plugins. It takes 310 Used to clean up the clones of repos which are not used by any plugins. It takes
309 no arguments. When this is run, it lists out the repo-clones that are available 311 no arguments. When this is run, it lists out the repo-clones that are available
310 but are not used by any plugin *currently loaded*. 312 but are not used by any plugin *currently loaded*.
311 313
312 This command, by default asks for confirmation before deleting the unused 314 This command, by default asks for confirmation before deleting the unused
313 clones. If the `--force` argument is given, then this confirmation is not asked. 315 clones. If the `--force` argument is given, then this confirmation is not asked.
314 It straight away deletes all the unused clones. This option makes this command 316 It straight away deletes all the unused clones. This option makes this command
315 usable in a non-interactive fashion. 317 usable in a non-interactive fashion.
316 318
317 ### antigen-lib 319 ### antigen-lib
318 320
319 This is a shortcut to 321 This is a shortcut to
320 322
321 antigen-bundle --loc=lib 323 antigen-bundle --loc=lib
322 324
323 So, it basically installs the oh-my-zsh's library as a bundle. Please note that 325 So, it basically installs the oh-my-zsh's library as a bundle. Please note that
324 this assumes that the `ANTIGEN_DEFAULT_REPO_URL` is set to the oh-my-zsh repo or 326 this assumes that the `ANTIGEN_DEFAULT_REPO_URL` is set to the oh-my-zsh repo or
325 a fork of that repo. If you want to specify the `url` too, then you can't use 327 a fork of that repo. If you want to specify the `url` too, then you can't use
326 the `antigen-lib` short cut. You have to do that directly with the 328 the `antigen-lib` short cut. You have to do that directly with the
327 `antigen-bundle` command. 329 `antigen-bundle` command.
328 330
329 This is present only for legacy reasons and *might* (or might not) be removed in 331 This is present only for legacy reasons and *might* (or might not) be removed in
330 the future. 332 the future.
331 333
332 Use 334 Use
333 335
334 antigen-lib 336 antigen-lib
335 337
336 in your `.zshrc`, before any `antigen-bundle` declarations. It takes no 338 in your `.zshrc`, before any `antigen-bundle` declarations. It takes no
337 arguments. 339 arguments.
338 340
339 ### antigen-theme 341 ### antigen-theme
340 342
341 Used for switching the prompt theme. Invoke it with the name of the theme you 343 Used for switching the prompt theme. Invoke it with the name of the theme you
342 want to use. 344 want to use.
343 345
344 antigen-theme fox 346 antigen-theme fox
345 347
346 Currently, themes are pulled from robbyrussell's oh-my-zsh repo, but it will 348 Currently, themes are pulled from robbyrussell's oh-my-zsh repo, but it will
347 support getting themes from other repos as well in the future. 349 support getting themes from other repos as well in the future.
348 350
349 You can use this command to change your theme on the fly in your shell. Go on, 351 You can use this command to change your theme on the fly in your shell. Go on,
350 try out a few themes in your shell before you set it in your `.zshrc`. 352 try out a few themes in your shell before you set it in your `.zshrc`.
351 353
352 ### antigen-apply 354 ### antigen-apply
353 355
354 You have to add this command after defining all bundles you need, in your zshrc. 356 You have to add this command after defining all bundles you need, in your zshrc.
355 The completions defined by your bundles will be loaded at this step. 357 The completions defined by your bundles will be loaded at this step.
356 358
357 It is possible to load completions as and when a bundle is specified with the 359 It is possible to load completions as and when a bundle is specified with the
358 bundle command, in which case this command would not be necessary. But loading 360 bundle command, in which case this command would not be necessary. But loading
359 the completions is a time-consuming process and your shell will start noticeably 361 the completions is a time-consuming process and your shell will start noticeably
360 slow if you have a good number of bundle specifications. 362 slow if you have a good number of bundle specifications.
361 363
362 However, if you're a zsh expert and can suggest a way so that this would not be 364 However, if you're a zsh expert and can suggest a way so that this would not be
363 necessary, I am very interested in discussing it. Please open up an issue with 365 necessary, I am very interested in discussing it. Please open up an issue with
364 your details. Thanks. 366 your details. Thanks.
365 367
366 ### antigen-help 368 ### antigen-help
367 369
368 This exists so that there can be some help right in the command line. Currently 370 This exists so that there can be some help right in the command line. Currently
369 it doesn't provide much help other than redirecting you to the project page for 371 it doesn't provide much help other than redirecting you to the project page for
370 documentation. It is intended to provide more meaning and sub-command specific 372 documentation. It is intended to provide more meaning and sub-command specific
371 help in the future. 373 help in the future.
372 374
373 I could use some help here as I'm not that good at writing documentation that 375 I could use some help here as I'm not that good at writing documentation that
374 looks good as output on the command line. 376 looks good as output on the command line.
375 377
376 ### antigen 378 ### antigen
377 379
378 This is a parent command that mainly exists for convenience. The idea is the 380 This is a parent command that mainly exists for convenience. The idea is the
379 following two are the same. 381 following two are the same.
380 382
381 antigen-list 383 antigen-list
382 antigen list 384 antigen list
383 385
384 and 386 and
385 387
386 antigen-help 388 antigen-help
387 antigen help 389 antigen help
388 390
389 Because of this, we can create aliases like 391 Because of this, we can create aliases like
390 392
391 alias a=antigen 393 alias a=antigen
392 alias an=antigen 394 alias an=antigen
393 395
394 and run the antigen commands without making them look annoyingly long. 396 and run the antigen commands without making them look annoyingly long.
395 397
396 a bundle ruby 398 a bundle ruby
397 a theme candy 399 a theme candy
398 a list 400 a list
399 401
400 And even... 402 And even...
401 403
402 an update 404 an update
403 405
404 ## Configuration 406 ## Configuration
405 407
406 The following environment variables can be set to customize the behavior of 408 The following environment variables can be set to customize the behavior of
407 antigen. Make sure you set them *before* source-ing `antigen.zsh`. 409 antigen. Make sure you set them *before* source-ing `antigen.zsh`.
408 410
409 `ANTIGEN_DEFAULT_REPO_URL` &mdash; This is the default repository url that is 411 `ANTIGEN_DEFAULT_REPO_URL` &mdash; This is the default repository url that is
410 used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo, 412 used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo,
411 but you can set this to the fork url of your own fork. 413 but you can set this to the fork url of your own fork.
412 414
413 `ADOTDIR` &mdash; This directory is used to store all the repo clones, your 415 `ADOTDIR` &mdash; This directory is used to store all the repo clones, your
414 bundles, themes, caches and everything else antigen requires to run smoothly. 416 bundles, themes, caches and everything else antigen requires to run smoothly.
415 Defaults to `$HOME/.antigen`. 417 Defaults to `$HOME/.antigen`.
416 418
417 **Note**: `ANTIGEN_REPO_CACHE` & `ANTIGEN_BUNDLE_DIR` &mdash; These variables 419 **Note**: `ANTIGEN_REPO_CACHE` & `ANTIGEN_BUNDLE_DIR` &mdash; These variables
418 were used previously but are now removed. Please use `ADOTDIR` instead, as 420 were used previously but are now removed. Please use `ADOTDIR` instead, as
419 mentioned above. 421 mentioned above.
420 422
421 ## Running the tests 423 ## Running the tests
422 424
423 All the tests are in the `tests` folder and are run using the [cram]() test 425 All the tests are in the `tests` folder and are run using the [cram]() test
424 system. Once you have cram installed, you can run the tests as 426 system. Once you have cram installed, you can run the tests as
425 427
426 make 428 make
427 429
428 or 430 or
429 431
430 make tests 432 make tests
431 433
432 If you are making a feature addition, I'd really appreciate if you can add a 434 If you are making a feature addition, I'd really appreciate if you can add a
433 test for your feature. Even if you can add a test for an existing feature, that 435 test for your feature. Even if you can add a test for an existing feature, that
434 would be great as the tests are currently seriously lagging behind the full 436 would be great as the tests are currently seriously lagging behind the full
435 functionality of antigen. 437 functionality of antigen.
436 438
437 ## Notes on writing plugins 439 ## Notes on writing plugins
438 440
439 If you are just going to write a single `.sh` file with the goodness you want to 441 If you are just going to write a single `.sh` file with the goodness you want to
440 create, just forget about this and go do that. Antigen will work just find with 442 create, just forget about this and go do that. Antigen will work just find with
441 such a plugin. 443 such a plugin.
442 444
443 If you want to know how antigen loads the plugins, do continue. 445 If you want to know how antigen loads the plugins, do continue.
444 446
445 Firstly, antigen looks for a `*.plugin.zsh` file in the plugin directory. If 447 Firstly, antigen looks for a `*.plugin.zsh` file in the plugin directory. If
446 present, it will source *only* this script. Nothing else is sourced. 448 present, it will source *only* this script. Nothing else is sourced.
447 449
448 Otherwise, it looks for `*.zsh` files and if there are any, *all* of them are 450 Otherwise, it looks for `*.zsh` files and if there are any, *all* of them are
449 sourced. The order in which they are sourced is not currently defined. Please 451 sourced. The order in which they are sourced is not currently defined. Please
450 don't rely on this order. Nothing else is sourced after all the `*.zsh` scripts. 452 don't rely on this order. Nothing else is sourced after all the `*.zsh` scripts.
451 453
452 If no `*.zsh` files are present, it finally looks for any `*.sh` files and 454 If no `*.zsh` files are present, it finally looks for any `*.sh` files and
453 sources *all* of them. Again, the order in which they are sourced in not 455 sources *all* of them. Again, the order in which they are sourced in not
454 currently defined. 456 currently defined.
455 457
456 No matter which (or none) of the above happen to be sourced, this plugin 458 No matter which (or none) of the above happen to be sourced, this plugin
457 directory is added to the zsh's function path (`$fpath`) so that any completions 459 directory is added to the zsh's function path (`$fpath`) so that any completions
458 in it are loaded. One exception to this rule is that if this plugin is a prompt 460 in it are loaded. One exception to this rule is that if this plugin is a prompt
459 theme. In which case the theme script is just sourced and nothing else is done. 461 theme. In which case the theme script is just sourced and nothing else is done.
460 462
461 ## Meta 463 ## Meta
462 464
463 ### Helping out 465 ### Helping out
464 466
465 Antigen is licensed with the [MIT License][license]. To contribute, just fork, 467 Antigen is licensed with the [MIT License][license]. To contribute, just fork,
466 make changes and send a pull request. If its a rather long/complicated change, 468 make changes and send a pull request. If its a rather long/complicated change,
467 please consider opening an [issue][] first so we can discuss it out. 469 please consider opening an [issue][] first so we can discuss it out.
468 470
469 ### Feedback please 471 ### Feedback please
470 472
471 Any comments/suggestions/feedback welcome. Please join the discussion on the 473 Any comments/suggestions/feedback welcome. Please join the discussion on the
472 [reddit page][] of this project. Also, follow me on twitter, 474 [reddit page][] of this project. Also, follow me on twitter,
473 [@sharat87](twitter). 475 [@sharat87](twitter).
474 476
475 [Vundle]: https://github.com/gmarik/vundle 477 [Vundle]: https://github.com/gmarik/vundle
476 [page on themes]: https://github.com/robbyrussell/oh-my-zsh/wiki/Themes 478 [page on themes]: https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
477 [syntax highlighting plugin]: https://github.com/zsh-users/zsh-syntax-highlighting 479 [syntax highlighting plugin]: https://github.com/zsh-users/zsh-syntax-highlighting
478 [autoenv]: https://github.com/kennethreitz/autoenv 480 [autoenv]: https://github.com/kennethreitz/autoenv
479 [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh 481 [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh
480 [cram]: https://bitheap.org/cram/ 482 [cram]: https://bitheap.org/cram/
481 [issue]: https://github.com/sharat87/antigen/issues 483 [issue]: https://github.com/sharat87/antigen/issues
482 [license]: http://mit.sharats.me 484 [license]: http://mit.sharats.me
483 [reddit page]: http://www.reddit.com/r/commandline/comments/u4f26/antigen_a_plugin_manager_for_zsh_shell/ 485 [reddit page]: http://www.reddit.com/r/commandline/comments/u4f26/antigen_a_plugin_manager_for_zsh_shell/
484 [twitter]: http://twitter.com/sharat87 486 [twitter]: http://twitter.com/sharat87
485 487
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> 5 # <repo-url>, <plugin-location>, <bundle-type>
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 8
9 # Syntaxes 9 # Syntaxes
10 # antigen-bundle <url> [<loc>=/] 10 # antigen-bundle <url> [<loc>=/]
11 # Keyword only arguments: 11 # Keyword only arguments:
12 # branch - The branch of the repo to use for this bundle. 12 # branch - The branch of the repo to use for this bundle.
13 antigen-bundle () { 13 antigen-bundle () {
14 14
15 # Bundle spec arguments' default values. 15 # Bundle spec arguments' default values.
16 local url="$ANTIGEN_DEFAULT_REPO_URL" 16 local url="$ANTIGEN_DEFAULT_REPO_URL"
17 local loc=/ 17 local loc=/
18 local branch= 18 local branch=
19 local no_local_clone=false 19 local no_local_clone=false
20 local btype=plugin 20 local btype=plugin
21 21
22 # Set spec values based on the positional arguments. 22 # Set spec values based on the positional arguments.
23 local position_args 23 local position_args
24 position_args=(url loc) 24 position_args=(url loc)
25 local i=1 25 local i=1
26 while ! [[ -z $1 || $1 == --* ]]; do 26 while ! [[ -z $1 || $1 == --* ]]; do
27 local arg_name="${position_args[$i]}" 27 local arg_name="${position_args[$i]}"
28 local arg_value="$1" 28 local arg_value="$1"
29 eval "local $arg_name='$arg_value'" 29 eval "local $arg_name='$arg_value'"
30 shift 30 shift
31 i=$(($i + 1)) 31 i=$(($i + 1))
32 done 32 done
33 33
34 # Set spec values from keyword arguments, if any. The remaining arguments 34 # Set spec values from keyword arguments, if any. The remaining arguments
35 # are all assumed to be keyword arguments. 35 # are all assumed to be keyword arguments.
36 while [[ $1 == --* ]]; do 36 while [[ $1 == --* ]]; do
37 # Remove the `--` at the start. 37 # Remove the `--` at the start.
38 local arg="${1#--}" 38 local arg="${1#--}"
39 39
40 if [[ $arg != *=* ]]; then 40 if [[ $arg != *=* ]]; then
41 arg="$arg=true" 41 arg="$arg=true"
42 fi 42 fi
43 43
44 # Get the name of the arg and replace the `-`'s to `_`'s. 44 # Get the name of the arg and replace the `-`'s to `_`'s.
45 local arg_name="${${arg%\=*}//-/_}" 45 local arg_name="${${arg%\=*}//-/_}"
46 46
47 # Get the value of the arg. 47 # Get the value of the arg.
48 local arg_value="${arg#*\=}" 48 local arg_value="${arg#*\=}"
49 49
50 eval "local $arg_name='$arg_value'" 50 eval "local $arg_name='$arg_value'"
51 shift 51 shift
52 done 52 done
53 53
54 # Check if url is just the plugin name. Super short syntax. 54 # Check if url is just the plugin name. Super short syntax.
55 if [[ "$url" != */* ]]; then 55 if [[ "$url" != */* ]]; then
56 loc="plugins/$url" 56 loc="plugins/$url"
57 url="$ANTIGEN_DEFAULT_REPO_URL" 57 url="$ANTIGEN_DEFAULT_REPO_URL"
58 fi 58 fi
59 59
60 # Resolve the url. 60 # Resolve the url.
61 url="$(-antigen-resolve-bundle-url "$url")" 61 url="$(-antigen-resolve-bundle-url "$url")"
62 62
63 # Add the branch information to the url. 63 # Add the branch information to the url.
64 if [[ ! -z $branch ]]; then 64 if [[ ! -z $branch ]]; then
65 url="$url|$branch" 65 url="$url|$branch"
66 fi 66 fi
67 67
68 # The `make_local_clone` variable better represents whether there should be 68 # The `make_local_clone` variable better represents whether there should be
69 # a local clone made. If the url is a local absolute path and no_local_clone 69 # a local clone made. For cloning to be avoided, firstly, the `$url` should
70 # is true, then and only then, there should be no cloning taking place. 70 # be an absolute local path and `$branch` should be empty. In addition to
71 # these two conditions, either the `--no-local-clone` option should be
72 # given, or `$url` should not a git repo.
71 local make_local_clone=true 73 local make_local_clone=true
72 if [[ $url == /* && ( $no_local_clone == true || ! -d $url/.git ) ]]; then 74 if [[ $url == /* && -z $branch \
75 && ( $no_local_clone == true || ! -d $url/.git ) ]]; then
73 make_local_clone=false 76 make_local_clone=false
74 fi 77 fi
75 78
76 # Add it to the record. 79 # Add it to the record.
77 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype $make_local_clone" 80 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype $make_local_clone"
78 81
79 # Ensure a clone exists for this repo, if needed. 82 # Ensure a clone exists for this repo, if needed.
80 if $make_local_clone; then 83 if $make_local_clone; then
81 -antigen-ensure-repo "$url" 84 -antigen-ensure-repo "$url"
82 fi 85 fi
83 86
84 # Load the plugin. 87 # Load the plugin.
85 -antigen-load "$url" "$loc" "$btype" "$make_local_clone" 88 -antigen-load "$url" "$loc" "$btype" "$make_local_clone"
86 89
87 } 90 }
88 91
89 -antigen-resolve-bundle-url () { 92 -antigen-resolve-bundle-url () {
90 # Given an acceptable short/full form of a bundle's repo url, this function 93 # Given an acceptable short/full form of a bundle's repo url, this function
91 # echoes the full form of the repo's clone url. 94 # echoes the full form of the repo's clone url.
92 95
93 local url="$1" 96 local url="$1"
94 97
95 # Expand short github url syntax: `username/reponame` 98 # Expand short github url syntax: `username/reponame`
96 if [[ $url != git://* && \ 99 if [[ $url != git://* && \
97 $url != https://* && \ 100 $url != https://* && \
98 $url != /* && \ 101 $url != /* && \
99 $url != git@github.com:*/* 102 $url != git@github.com:*/*
100 ]]; then 103 ]]; then
101 url="https://github.com/${url%.git}.git" 104 url="https://github.com/${url%.git}.git"
102 fi 105 fi
103 106
104 echo "$url" 107 echo "$url"
105 } 108 }
106 109
107 antigen-bundles () { 110 antigen-bundles () {
108 # Bulk add many bundles at one go. Empty lines and lines starting with a `#` 111 # Bulk add many bundles at one go. Empty lines and lines starting with a `#`
109 # are ignored. Everything else is given to `antigen-bundle` as is, no 112 # are ignored. Everything else is given to `antigen-bundle` as is, no
110 # quoting rules applied. 113 # quoting rules applied.
111 114
112 local line 115 local line
113 116
114 grep -v '^\s*$\|^#' | while read line; do 117 grep -v '^\s*$\|^#' | while read line; do
115 # Using `eval` so that we can use the shell-style quoting in each line 118 # Using `eval` so that we can use the shell-style quoting in each line
116 # piped to `antigen-bundles`. 119 # piped to `antigen-bundles`.
117 eval "antigen-bundle $line" 120 eval "antigen-bundle $line"
118 done 121 done
119 } 122 }
120 123
121 antigen-update () { 124 antigen-update () {
122 # Update your bundles, i.e., `git pull` in all the plugin repos. 125 # Update your bundles, i.e., `git pull` in all the plugin repos.
123 -antigen-echo-record \ 126 -antigen-echo-record \
124 | awk '{print $1}' \ 127 | awk '{print $1}' \
125 | sort -u \ 128 | sort -u \
126 | while read url; do 129 | while read url; do
127 echo "**** Pulling $url" 130 echo "**** Pulling $url"
128 -antigen-ensure-repo --update --verbose "$url" 131 -antigen-ensure-repo --update --verbose "$url"
129 echo 132 echo
130 done 133 done
131 } 134 }
132 135
133 -antigen-get-clone-dir () { 136 -antigen-get-clone-dir () {
134 # Takes a repo url and gives out the path that this url needs to be cloned 137 # Takes a repo url and gives out the path that this url needs to be cloned
135 # to. Doesn't actually clone anything. 138 # to. Doesn't actually clone anything.
136 # TODO: Memoize? 139 # TODO: Memoize?
137 140
138 # The url given. 141 # The url given.
139 local url="$1" 142 local url="$1"
140 143
141 # Echo the full path to the clone directory. 144 # Echo the full path to the clone directory.
142 echo -n $ADOTDIR/repos/ 145 echo -n $ADOTDIR/repos/
143 echo "$url" | sed \ 146 echo "$url" | sed \
144 -e 's./.-SLASH-.g' \ 147 -e 's./.-SLASH-.g' \
145 -e 's.:.-COLON-.g' \ 148 -e 's.:.-COLON-.g' \
146 -e 's.|.-PIPE-.g' 149 -e 's.|.-PIPE-.g'
147 } 150 }
148 151
149 -antigen-get-clone-url () { 152 -antigen-get-clone-url () {
150 # Takes a repo's clone dir and gives out the repo's original url that was 153 # Takes a repo's clone dir and gives out the repo's original url that was
151 # used to create the given directory path. 154 # used to create the given directory path.
152 # TODO: Memoize? 155 # TODO: Memoize?
153 echo "$1" | sed \ 156 echo "$1" | sed \
154 -e "s:^$ADOTDIR/repos/::" \ 157 -e "s:^$ADOTDIR/repos/::" \
155 -e 's.-SLASH-./.g' \ 158 -e 's.-SLASH-./.g' \
156 -e 's.-COLON-.:.g' \ 159 -e 's.-COLON-.:.g' \
157 -e 's.-PIPE-.|.g' 160 -e 's.-PIPE-.|.g'
158 } 161 }
159 162
160 -antigen-ensure-repo () { 163 -antigen-ensure-repo () {
161 164
162 # Ensure that a clone exists for the given repo url and branch. If the first 165 # Ensure that a clone exists for the given repo url and branch. If the first
163 # argument is `--update` and if a clone already exists for the given repo 166 # argument is `--update` and if a clone already exists for the given repo
164 # and branch, it is pull-ed, i.e., updated. 167 # and branch, it is pull-ed, i.e., updated.
165 168
166 # Argument defaults. 169 # Argument defaults.
167 # Check if we have to update. 170 # Check if we have to update.
168 local update=false 171 local update=false
169 # Verbose output. 172 # Verbose output.
170 local verbose=false 173 local verbose=false
171 174
172 # Load any boolean arguments specified. 175 # Load any boolean arguments specified.
173 while [[ $1 == --* ]]; do 176 while [[ $1 == --* ]]; do
174 eval "local '${1#--}=true'" 177 eval "local '${1#--}=true'"
175 shift 178 shift
176 done 179 done
177 180
178 # Get the clone's directory as per the given repo url and branch. 181 # Get the clone's directory as per the given repo url and branch.
179 local url="$1" 182 local url="$1"
180 local clone_dir="$(-antigen-get-clone-dir $url)" 183 local clone_dir="$(-antigen-get-clone-dir $url)"
181 184
182 # Clone if it doesn't already exist. 185 # Clone if it doesn't already exist.
183 if [[ ! -d $clone_dir ]]; then 186 if [[ ! -d $clone_dir ]]; then
184 git clone "${url%|*}" "$clone_dir" 187 git clone "${url%|*}" "$clone_dir"
185 elif $update; then 188 elif $update; then
186 # Save current revision. 189 # Save current revision.
187 old_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ 190 old_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \
188 rev-parse HEAD)" 191 rev-parse HEAD)"
189 # Pull changes if update requested. 192 # Pull changes if update requested.
190 git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ 193 git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \
191 pull 194 pull
192 # Get the new revision. 195 # Get the new revision.
193 new_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ 196 new_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \
194 rev-parse HEAD)" 197 rev-parse HEAD)"
195 fi 198 fi
196 199
197 # If its a specific branch that we want, checkout that branch. 200 # If its a specific branch that we want, checkout that branch.
198 if [[ $url == *\|* ]]; then 201 if [[ $url == *\|* ]]; then
199 git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ 202 git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \
200 checkout "${url#*|}" 203 checkout "${url#*|}"
201 fi 204 fi
202 205
203 if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then 206 if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then
204 echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. 207 echo Updated from ${old_rev:0:7} to ${new_rev:0:7}.
205 if $verbose; then 208 if $verbose; then
206 git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ 209 git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \
207 log --oneline --reverse --no-merges --stat '@{1}..' 210 log --oneline --reverse --no-merges --stat '@{1}..'
208 fi 211 fi
209 fi 212 fi
210 213
211 } 214 }
212 215
213 -antigen-load () { 216 -antigen-load () {
214 217
215 local url="$1" 218 local url="$1"
216 local loc="$2" 219 local loc="$2"
217 local btype="$3" 220 local btype="$3"
218 local make_local_clone="$4" 221 local make_local_clone="$4"
219 222
220 # The full location where the plugin is located. 223 # The full location where the plugin is located.
221 local location 224 local location
222 if $make_local_clone; then 225 if $make_local_clone; then
223 location="$(-antigen-get-clone-dir "$url")/$loc" 226 location="$(-antigen-get-clone-dir "$url")/$loc"
224 else 227 else
225 location="$url" 228 location="$url"
226 fi 229 fi
227 230
228 if [[ $btype == theme ]]; then 231 if [[ $btype == theme ]]; then
229 232
230 # Of course, if its a theme, the location would point to the script 233 # Of course, if its a theme, the location would point to the script
231 # file. 234 # file.
232 source "$location" 235 source "$location"
233 236
234 else 237 else
235 238
236 # Source the plugin script 239 # Source the plugin script
237 # FIXME: I don't know. Looks very very ugly. Needs a better 240 # FIXME: I don't know. Looks very very ugly. Needs a better
238 # implementation once tests are ready. 241 # implementation once tests are ready.
239 local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" 242 local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')"
240 243
241 if [[ -f $script_loc ]]; then 244 if [[ -f $script_loc ]]; then
242 # If we have a `*.plugin.zsh`, source it. 245 # If we have a `*.plugin.zsh`, source it.
243 source "$script_loc" 246 source "$script_loc"
244 247
245 elif [[ ! -z "$(ls "$location" | grep -m1 '\.zsh$')" ]]; then 248 elif [[ ! -z "$(ls "$location" | grep -m1 '\.zsh$')" ]]; then
246 # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` 249 # If there is no `*.plugin.zsh` file, source *all* the `*.zsh`
247 # files. 250 # files.
248 for script ($location/*.zsh(N)) source "$script" 251 for script ($location/*.zsh(N)) source "$script"
249 252
250 elif [[ ! -z "$(ls "$location" | grep -m1 '\.sh$')" ]]; then 253 elif [[ ! -z "$(ls "$location" | grep -m1 '\.sh$')" ]]; then
251 # If there are no `*.zsh` files either, we look for and source any 254 # If there are no `*.zsh` files either, we look for and source any
252 # `*.sh` files instead. 255 # `*.sh` files instead.
253 for script ($location/*.sh(N)) source "$script" 256 for script ($location/*.sh(N)) source "$script"
254 257
255 fi 258 fi
256 259
257 # Add to $fpath, for completion(s). 260 # Add to $fpath, for completion(s).
258 fpath=($location $fpath) 261 fpath=($location $fpath)
259 262
260 fi 263 fi
261 264
262 } 265 }
263 266
264 antigen-cleanup () { 267 antigen-cleanup () {
265 268
266 # Cleanup unused repositories. 269 # Cleanup unused repositories.
267 270
268 local force=false 271 local force=false
269 if [[ $1 == --force ]]; then 272 if [[ $1 == --force ]]; then
270 force=true 273 force=true
271 fi 274 fi
272 275
273 if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then 276 if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then
274 echo "You don't have any bundles." 277 echo "You don't have any bundles."
275 return 0 278 return 0
276 fi 279 fi
277 280
278 # Find directores in ADOTDIR/repos, that are not in the bundles record. 281 # Find directores in ADOTDIR/repos, that are not in the bundles record.
279 local unused_clones="$(comm -13 \ 282 local unused_clones="$(comm -13 \
280 <(-antigen-echo-record \ 283 <(-antigen-echo-record \
281 | awk '$4 == "true" {print $1}' \ 284 | awk '$4 == "true" {print $1}' \
282 | while read line; do 285 | while read line; do
283 -antigen-get-clone-dir "$line" 286 -antigen-get-clone-dir "$line"
284 done \ 287 done \
285 | sort -u) \ 288 | sort -u) \
286 <(ls -d "$ADOTDIR/repos/"* | sort -u))" 289 <(ls -d "$ADOTDIR/repos/"* | sort -u))"
287 290
288 if [[ -z $unused_clones ]]; then 291 if [[ -z $unused_clones ]]; then
289 echo "You don't have any unidentified bundles." 292 echo "You don't have any unidentified bundles."
290 return 0 293 return 0
291 fi 294 fi
292 295
293 echo 'You have clones for the following repos, but are not used.' 296 echo 'You have clones for the following repos, but are not used.'
294 echo "$unused_clones" \ 297 echo "$unused_clones" \
295 | while read line; do 298 | while read line; do
296 -antigen-get-clone-url "$line" 299 -antigen-get-clone-url "$line"
297 done \ 300 done \
298 | sed -e 's/^/ /' -e 's/|/, branch /' 301 | sed -e 's/^/ /' -e 's/|/, branch /'
299 302
300 if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then 303 if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then
301 echo 304 echo
302 echo 305 echo
303 echo "$unused_clones" | while read line; do 306 echo "$unused_clones" | while read line; do
304 echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." 307 echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..."
305 rm -rf "$line" 308 rm -rf "$line"
306 echo ' done.' 309 echo ' done.'
307 done 310 done
308 else 311 else
309 echo 312 echo
310 echo Nothing deleted. 313 echo Nothing deleted.
311 fi 314 fi
312 } 315 }
313 316
314 antigen-lib () { 317 antigen-lib () {
315 antigen-bundle --loc=lib 318 antigen-bundle --loc=lib
316 } 319 }
317 320
318 antigen-theme () { 321 antigen-theme () {
319 local name="${1:-robbyrussell}" 322 local name="${1:-robbyrussell}"
320 antigen-bundle --loc=themes/$name.zsh-theme --btype=theme 323 antigen-bundle --loc=themes/$name.zsh-theme --btype=theme
321 } 324 }
322 325
323 antigen-apply () { 326 antigen-apply () {
324 # Initialize completion. 327 # Initialize completion.
325 # TODO: Only load completions if there are any changes to the bundle 328 # TODO: Only load completions if there are any changes to the bundle
326 # repositories. 329 # repositories.
327 compinit -i 330 compinit -i
328 } 331 }
329 332
330 antigen-list () { 333 antigen-list () {
331 # List all currently installed bundles 334 # List all currently installed bundles
332 if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then 335 if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then
333 echo "You don't have any bundles." >&2 336 echo "You don't have any bundles." >&2
334 return 1 337 return 1
335 else 338 else
336 -antigen-echo-record | sort -u 339 -antigen-echo-record | sort -u
337 fi 340 fi
338 } 341 }
339 342
340 antigen-help () { 343 antigen-help () {
341 cat <<EOF 344 cat <<EOF
342 Antigen is a plugin management system for zsh. It makes it easy to grab awesome 345 Antigen is a plugin management system for zsh. It makes it easy to grab awesome
343 shell scripts and utilities, put up on github. For further details and complete 346 shell scripts and utilities, put up on github. For further details and complete
344 documentation, visit the project's page at 'http://antigen.sharats.me'. 347 documentation, visit the project's page at 'http://antigen.sharats.me'.
345 EOF 348 EOF
346 } 349 }
347 350
348 # A syntax sugar to avoid the `-` when calling antigen commands. With this 351 # A syntax sugar to avoid the `-` when calling antigen commands. With this
349 # function, you can write `antigen-bundle` as `antigen bundle` and so on. 352 # function, you can write `antigen-bundle` as `antigen bundle` and so on.
350 antigen () { 353 antigen () {
351 local cmd="$1" 354 local cmd="$1"
352 shift 355 shift
353 "antigen-$cmd" "$@" 356 "antigen-$cmd" "$@"
354 } 357 }
355 358
356 # Echo the bundle specs as in the record. The first line is not echoed since it 359 # Echo the bundle specs as in the record. The first line is not echoed since it
357 # is a blank line. 360 # is a blank line.
358 -antigen-echo-record () { 361 -antigen-echo-record () {
359 echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' 362 echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p'
360 } 363 }
361 364
362 -antigen-env-setup () { 365 -antigen-env-setup () {
363 # Pre-startup initializations 366 # Pre-startup initializations
364 -set-default ANTIGEN_DEFAULT_REPO_URL \ 367 -set-default ANTIGEN_DEFAULT_REPO_URL \
365 https://github.com/robbyrussell/oh-my-zsh.git 368 https://github.com/robbyrussell/oh-my-zsh.git
366 -set-default ADOTDIR $HOME/.antigen 369 -set-default ADOTDIR $HOME/.antigen
367 370
368 # Load the compinit module 371 # Load the compinit module
369 autoload -U compinit 372 autoload -U compinit
370 373
371 # Without the following, `compdef` function is not defined. 374 # Without the following, `compdef` function is not defined.
372 compinit -i 375 compinit -i
373 } 376 }
374 377
375 # Same as `export $1=$2`, but will only happen if the name specified by `$1` is 378 # Same as `export $1=$2`, but will only happen if the name specified by `$1` is
376 # not already set. 379 # not already set.
377 -set-default () { 380 -set-default () {
378 local arg_name="$1" 381 local arg_name="$1"
379 local arg_value="$2" 382 local arg_value="$2"
380 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" 383 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'"
381 } 384 }
382 385
383 -antigen-env-setup 386 -antigen-env-setup
384 387