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