Commit 2fe4683b32a1b7c466e33c4773c550f3b384d287
1 parent
3c5ff1c1e2
Update README with new command nomenclature.
Also renamed antigen-bundle-update to antigen-update for command name consistency.
Showing 2 changed files with 40 additions and 36 deletions Inline Diff
README.mkd
| 1 | # Antigen | 1 | # Antigen |
| 2 | 2 | ||
| 3 | Antigen is a small set of functions that help you easily manage your shell (zsh) | 3 | Antigen is a small set of functions that help you easily manage your shell (zsh) |
| 4 | plugins, called bundles. The concept is pretty much the same as bundles in a | 4 | plugins, called bundles. The concept is pretty much the same as bundles in a |
| 5 | typical vim+pathogen setup. Antigen is to zsh, what [Vundle][] is to vim. | 5 | typical vim+pathogen setup. Antigen is to zsh, what [Vundle][] is to vim. |
| 6 | 6 | ||
| 7 | **Please** note that antigen is currently is alpha stage and will have backwards | 7 | **Please** note that antigen is currently is alpha stage and will have backwards |
| 8 | incompatible changes now and then, until we have a pretty stable system we can | 8 | incompatible changes now and then, until we have a pretty stable system we can |
| 9 | reason about. **Please** read the commit comments of the changesets when you | 9 | reason about. **Please** read the commit comments of the changesets when you |
| 10 | pull a new version of antigen. | 10 | pull a new version of antigen. |
| 11 | 11 | ||
| 12 | # Quick Usage | 12 | # Quick Usage |
| 13 | 13 | ||
| 14 | First, clone this repo, probably as a submodule if you have your dotfiles in a | 14 | First, clone this repo, probably as a submodule if you have your dotfiles in a |
| 15 | git repo, | 15 | git repo, |
| 16 | 16 | ||
| 17 | git clone https://github.com/sharat87/antigen.git | 17 | git clone https://github.com/sharat87/antigen.git |
| 18 | 18 | ||
| 19 | The usage should be very familiar to you if you use Vundle. A typical `.zshrc` | 19 | The usage should be very familiar to you if you use Vundle. A typical `.zshrc` |
| 20 | might look like this | 20 | might look like this |
| 21 | 21 | ||
| 22 | source /path-to-antigen-clone/antigen.zsh | 22 | source /path-to-antigen-clone/antigen.zsh |
| 23 | 23 | ||
| 24 | # Load the oh-my-zsh's library. | 24 | # Load the oh-my-zsh's library. |
| 25 | bundle-lib | 25 | bundle-lib |
| 26 | 26 | ||
| 27 | # Bundles from the default repo (robbyrussell's oh-my-zsh). | 27 | # Bundles from the default repo (robbyrussell's oh-my-zsh). |
| 28 | bundle git | 28 | bundle git |
| 29 | bundle heroku | 29 | bundle heroku |
| 30 | bundle pip | 30 | bundle pip |
| 31 | bundle lein | 31 | bundle lein |
| 32 | bundle command-not-found | 32 | bundle command-not-found |
| 33 | 33 | ||
| 34 | # Syntax highlighting bundle. | 34 | # Syntax highlighting bundle. |
| 35 | bundle zsh-users/zsh-syntax-highlighting | 35 | bundle zsh-users/zsh-syntax-highlighting |
| 36 | 36 | ||
| 37 | # Load the theme. | 37 | # Load the theme. |
| 38 | bundle-theme robbyrussell | 38 | bundle-theme robbyrussell |
| 39 | 39 | ||
| 40 | # Tell antigen that you're done. | 40 | # Tell antigen that you're done. |
| 41 | bundle-apply | 41 | bundle-apply |
| 42 | 42 | ||
| 43 | Open your zsh with this zshrc and you should see all the bundles you defined | 43 | Open your zsh with this zshrc and you should see all the bundles you defined |
| 44 | here, getting installed. Once its done, you are ready to roll. The complete | 44 | here, getting installed. Once its done, you are ready to roll. The complete |
| 45 | syntax for the `bundle` command is discussed further down on this page. | 45 | syntax for the `bundle` command is discussed further down on this page. |
| 46 | 46 | ||
| 47 | # Motivation | 47 | # Motivation |
| 48 | 48 | ||
| 49 | If you use zsh and [oh-my-zsh][], you know that having many different plugins | 49 | If you use zsh and [oh-my-zsh][], you know that having many different plugins |
| 50 | that are developed by many different authors in a single (sub)repo is not a very | 50 | that are developed by many different authors in a single (sub)repo is not a very |
| 51 | easy to maintain. There are some really fantastic plugins and utilities in | 51 | easy to maintain. There are some really fantastic plugins and utilities in |
| 52 | oh-my-zsh, but having them all in a single repo doesn't really scale well. And I | 52 | oh-my-zsh, but having them all in a single repo doesn't really scale well. And I |
| 53 | admire robbyrussell's efforts for reviewing and merging the gigantic number of | 53 | admire robbyrussell's efforts for reviewing and merging the gigantic number of |
| 54 | pull requests the project gets. It needs a better way of plugin management. | 54 | pull requests the project gets. It needs a better way of plugin management. |
| 55 | 55 | ||
| 56 | This was discussed on [a][1] [few][2] [issues][3], but it doesn't look like | 56 | This was discussed on [a][1] [few][2] [issues][3], but it doesn't look like |
| 57 | there was any progress made. So, I'm trying to start this off with antigen, | 57 | there was any progress made. So, I'm trying to start this off with antigen, |
| 58 | hoping to better this situation. Please note that I'm by no means a zsh or any | 58 | hoping to better this situation. Please note that I'm by no means a zsh or any |
| 59 | shell script expert (far from it). | 59 | shell script expert (far from it). |
| 60 | 60 | ||
| 61 | [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465 | 61 | [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465 |
| 62 | [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377 | 62 | [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377 |
| 63 | [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014 | 63 | [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014 |
| 64 | 64 | ||
| 65 | Inspired by vundle, antigen can pull oh-my-zsh style plugins from various github | 65 | Inspired by vundle, antigen can pull oh-my-zsh style plugins from various github |
| 66 | repositories. You are not limited to use plugins from the oh-my-zsh repository | 66 | repositories. You are not limited to use plugins from the oh-my-zsh repository |
| 67 | only and you don't need to maintain your own fork and pull from upstream every | 67 | only and you don't need to maintain your own fork and pull from upstream every |
| 68 | now and then. | 68 | now and then. |
| 69 | 69 | ||
| 70 | Antigen also lets you switch the prompt theme with one command, just like that | 70 | Antigen also lets you switch the prompt theme with one command, just like that |
| 71 | 71 | ||
| 72 | bundle-theme candy | 72 | bundle-theme candy |
| 73 | 73 | ||
| 74 | and your prompt is changed, just for this session of course. | 74 | and your prompt is changed, just for this session of course. |
| 75 | 75 | ||
| 76 | # Commands | 76 | # Commands |
| 77 | 77 | ||
| 78 | ## bundle | 78 | ## antigen-bundle |
| 79 | 79 | ||
| 80 | This command tells antigen to install (if not already installed) and load the | 80 | This command tells antigen to install (if not already installed) and load the |
| 81 | given plugin. The simplest usage follows the following syntax. | 81 | given plugin. The simplest usage follows the following syntax. |
| 82 | 82 | ||
| 83 | bundle <plugin-name> | 83 | antigen-bundle <plugin-name> |
| 84 | 84 | ||
| 85 | This will install the `plugins/<name>` directory from [robbyrussell's | 85 | This will install the `plugins/<name>` directory from [robbyrussell's |
| 86 | oh-my-zsh][oh-my-zsh] (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`). | 86 | oh-my-zsh][oh-my-zsh] (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`). |
| 87 | 87 | ||
| 88 | However, the above is just syntax sugar for the extended syntax of the `bundle` | 88 | However, the above is just syntax sugar for the extended syntax of the |
| 89 | command. | 89 | `antigen-bundle` command. |
| 90 | 90 | ||
| 91 | bundle [<url> [<loc>]] | 91 | antigen-bundle [<url> [<loc>]] |
| 92 | 92 | ||
| 93 | where `<url>` is the repository url and it defaults to [robbyrussell's | 93 | where `<url>` is the repository url and it defaults to [robbyrussell's |
| 94 | oh-my-zsh][oh-my-zsh] repo (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL` | 94 | oh-my-zsh][oh-my-zsh] repo (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL` |
| 95 | discussed further down). `<loc>` is the path under this repository which has the | 95 | discussed further down). `<loc>` is the path under this repository which has the |
| 96 | zsh plugin. This is typically the directory that contains a `*.plugin.zsh` file, | 96 | zsh plugin. This is typically the directory that contains a `*.plugin.zsh` file, |
| 97 | but it could contain a completion file or just many `*.zsh` files to be sourced. | 97 | but it could contain a completion file or just many `*.zsh` files to be sourced. |
| 98 | `<loc>` defaults to `/`, which indicates the repository itself is a plugin. | 98 | `<loc>` defaults to `/`, which indicates the repository itself is a plugin. |
| 99 | 99 | ||
| 100 | An example invocation would be | 100 | An example invocation would be |
| 101 | 101 | ||
| 102 | # The following is the same as `bundle ant`. But for demonstration purposes, | 102 | # The following is the same as `antigen-bundle ant`. But for demonstration |
| 103 | # we use the extended syntax here. | 103 | # purposes, we use the extended syntax here. |
| 104 | bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant | 104 | antigen-bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant |
| 105 | 105 | ||
| 106 | This would install the ant plugin from robbyrussell's oh-my-zsh repo. Of course, | 106 | This would install the ant plugin from robbyrussell's oh-my-zsh repo. Of course, |
| 107 | github url's can be shortened. | 107 | github url's can be shortened. |
| 108 | 108 | ||
| 109 | bundle robbyrussell/oh-my-zsh plugins/ant | 109 | antigen-bundle robbyrussell/oh-my-zsh plugins/ant |
| 110 | 110 | ||
| 111 | And since this repo is the default, even that isn't necessary. But we can't | 111 | And since this repo is the default, even that isn't necessary. But we can't |
| 112 | specify the `loc` without giving the first argument. | 112 | specify the `loc` without giving the first argument. |
| 113 | 113 | ||
| 114 | For this and a few other reasons, `bundle` also supports a simple keyword | 114 | For this and a few other reasons, `antigen-bundle` also supports a simple |
| 115 | argument syntax, using which we can rewrite the above as | 115 | keyword argument syntax, using which we can rewrite the above as |
| 116 | 116 | ||
| 117 | bundle --loc=plugins/ant | 117 | antigen-bundle --loc=plugins/ant |
| 118 | 118 | ||
| 119 | Which picks up the default for the `url` argument, and uses the `loc` given to | 119 | Which picks up the default for the `url` argument, and uses the `loc` given to |
| 120 | it. | 120 | it. |
| 121 | 121 | ||
| 122 | *Note* that you can mix and match positional and keyword arguments. But you | 122 | *Note* that you can mix and match positional and keyword arguments. But you |
| 123 | can't have positional arguments after keyword arguments. | 123 | can't have positional arguments after keyword arguments. |
| 124 | 124 | ||
| 125 | bundle robbyrussell/oh-my-zsh --loc=plugins/ant | 125 | antigen-bundle robbyrussell/oh-my-zsh --loc=plugins/ant |
| 126 | 126 | ||
| 127 | And keyword arguments don't care about the order in which the arguments are | 127 | And keyword arguments don't care about the order in which the arguments are |
| 128 | specified. The following is perfectly valid. | 128 | specified. The following is perfectly valid. |
| 129 | 129 | ||
| 130 | bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh | 130 | antigen-bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh |
| 131 | 131 | ||
| 132 | In addition to the above discussed arguments, `bundle` also takes a `btype` | 132 | In addition to the above discussed arguments, `antigen-bundle` also takes a |
| 133 | keyword-only argument, that is used internally. You shouldn't be concerned with | 133 | `btype` keyword-only argument, that is used internally. You shouldn't be |
| 134 | this argument, its only used internally and will probably go away in the future. | 134 | concerned with this argument, its only used internally and will probably go away |
| 135 | It indicates whether the bundle is a theme or a simple plugin. | 135 | in the future. It indicates whether the bundle is a theme or a simple plugin. |
| 136 | 136 | ||
| 137 | You can use this `bundle` command not just from your `.zshrc`, but also from | 137 | You can use this `antigen-bundle` command not just from your `.zshrc`, but also |
| 138 | your shell environment. This allows you to install plugins on the fly and try | 138 | from your shell environment. This allows you to install plugins on the fly and |
| 139 | them out. Of course if you want a bundle to be available every time you open a | 139 | try them out. Of course if you want a bundle to be available every time you open |
| 140 | shell, put it in your `.zshrc`. | 140 | a shell, put it in your `.zshrc`. |
| 141 | 141 | ||
| 142 | ## bundle-update | 142 | ## antigen-update |
| 143 | 143 | ||
| 144 | This is something you might not want to put in your `.zshrc`. Instead, run it | 144 | This is something you might not want to put in your `.zshrc`. Instead, run it |
| 145 | occasionally to update all your plugins. It doesn't take any arguments. | 145 | occasionally to update all your plugins. It doesn't take any arguments. |
| 146 | 146 | ||
| 147 | bundle-update | 147 | antigen-update |
| 148 | 148 | ||
| 149 | Please note that the updates that are downloaded are not immediately available. | 149 | Please note that the updates that are downloaded are not immediately available. |
| 150 | You have to open a new shell to be able to see the changes. This is a limitation | 150 | You have to open a new shell to be able to see the changes. This is a limitation |
| 151 | by design since reloading all the plugins *might* have some nasty side effects | 151 | by design since reloading all the plugins *might* have some nasty side effects |
| 152 | that may not be immediately apparent. Let's just say it can make your shell act | 152 | that may not be immediately apparent. Let's just say it can make your shell act |
| 153 | real quirky. | 153 | real quirky. |
| 154 | 154 | ||
| 155 | ## bundle-list | 155 | **Please note**: This command is not for updating *antigen* itself. Its for |
| 156 | updating the bundles you are using with antigen. | ||
| 157 | |||
| 158 | ## antigen-list | ||
| 156 | 159 | ||
| 157 | Use this command to list out the currently *loaded* plugins. Keep in mind that | 160 | Use this command to list out the currently *loaded* plugins. Keep in mind that |
| 158 | this includes any bundles installed on-the-fly. | 161 | this includes any bundles installed on-the-fly. |
| 159 | 162 | ||
| 160 | Takes no arguments. Gives out the repo url and the plugin's location under the | 163 | Takes no arguments. Gives out the repo url and the plugin's location under the |
| 161 | repo. | 164 | repo. |
| 162 | 165 | ||
| 163 | ## bundle-cleanup | 166 | ## antigen-cleanup |
| 164 | 167 | ||
| 165 | Used to clean up the clones of repos which are not used by any plugins. It takes | 168 | Used to clean up the clones of repos which are not used by any plugins. It takes |
| 166 | no arguments. When this is run, it lists out the repo-clones that are available | 169 | no arguments. When this is run, it lists out the repo-clones that are available |
| 167 | but are not used by any plugin *currently loaded*. | 170 | but are not used by any plugin *currently loaded*. |
| 168 | 171 | ||
| 169 | This command currently cannot run in a non-interactive mode. So it won't be very | 172 | This command currently cannot run in a non-interactive mode. So it won't be very |
| 170 | pleasant to use it in your `.zshrc`. | 173 | pleasant to use it in your `.zshrc`. |
| 171 | 174 | ||
| 172 | ## bundle-lib | 175 | ## antigen-lib |
| 173 | 176 | ||
| 174 | This is a shortcut to | 177 | This is a shortcut to |
| 175 | 178 | ||
| 176 | bundle --loc=lib | 179 | antigen-bundle --loc=lib |
| 177 | 180 | ||
| 178 | So, it basically installs the oh-my-zsh's library as a bundle. Please note that | 181 | So, it basically installs the oh-my-zsh's library as a bundle. Please note that |
| 179 | this assumes that the `ANTIGEN_DEFAULT_REPO_URL` is set to the oh-my-zsh repo or | 182 | this assumes that the `ANTIGEN_DEFAULT_REPO_URL` is set to the oh-my-zsh repo or |
| 180 | a fork of that repo. If you want to specify the `url` too, then you can't use | 183 | a fork of that repo. If you want to specify the `url` too, then you can't use |
| 181 | the `bundle-lib` short cut. You have to do that directly with the `bundle` | 184 | the `antigen-lib` short cut. You have to do that directly with the |
| 182 | command. | 185 | `antigen-bundle` command. |
| 183 | 186 | ||
| 184 | This is present only for legacy reasons and *might* (or might not) be removed in | 187 | This is present only for legacy reasons and *might* (or might not) be removed in |
| 185 | the future. | 188 | the future. |
| 186 | 189 | ||
| 187 | Use | 190 | Use |
| 188 | 191 | ||
| 189 | bundle-lib | 192 | antigen-lib |
| 190 | 193 | ||
| 191 | in your `.zshrc`, before any `bundle` declarations. It takes no arguments. | 194 | in your `.zshrc`, before any `antigen-bundle` declarations. It takes no |
| 195 | arguments. | ||
| 192 | 196 | ||
| 193 | ## bundle-theme | 197 | ## antigen-theme |
| 194 | 198 | ||
| 195 | Used for switching the prompt theme. Invoke it with the name of the theme you | 199 | Used for switching the prompt theme. Invoke it with the name of the theme you |
| 196 | want to use. | 200 | want to use. |
| 197 | 201 | ||
| 198 | bundle-theme fox | 202 | antigen-theme fox |
| 199 | 203 | ||
| 200 | Currently, themes are pulled from robbyrussell's oh-my-zsh repo, but it will | 204 | Currently, themes are pulled from robbyrussell's oh-my-zsh repo, but it will |
| 201 | support getting themes from other repos as well in the future. | 205 | support getting themes from other repos as well in the future. |
| 202 | 206 | ||
| 203 | You can use this command to change your theme on the fly in your shell. Go on, | 207 | You can use this command to change your theme on the fly in your shell. Go on, |
| 204 | try out a few themes in your shell before you set it in your `.zshrc`. | 208 | try out a few themes in your shell before you set it in your `.zshrc`. |
| 205 | 209 | ||
| 206 | ## bundle-apply | 210 | ## antigen-apply |
| 207 | 211 | ||
| 208 | You have to add this command after defining all bundles you need, in your zshrc. | 212 | You have to add this command after defining all bundles you need, in your zshrc. |
| 209 | The completions defined by your bundles will be loaded at this step. | 213 | The completions defined by your bundles will be loaded at this step. |
| 210 | 214 | ||
| 211 | It is possible to load completions as and when a bundle is specified with the | 215 | It is possible to load completions as and when a bundle is specified with the |
| 212 | bundle command, in which case this command would not be necessary. But loading | 216 | bundle command, in which case this command would not be necessary. But loading |
| 213 | the completions is a time-consuming process and your shell will start noticeably | 217 | the completions is a time-consuming process and your shell will start noticeably |
| 214 | slow if you have a good number of bundle specifications. | 218 | slow if you have a good number of bundle specifications. |
| 215 | 219 | ||
| 216 | However, if you're a zsh expert and can suggest a way so that this would not be | 220 | However, if you're a zsh expert and can suggest a way so that this would not be |
| 217 | necessary, I am very interested in discussing it. Please open up an issue with | 221 | necessary, I am very interested in discussing it. Please open up an issue with |
| 218 | your details. Thanks. | 222 | your details. Thanks. |
| 219 | 223 | ||
| 220 | # Configuration | 224 | # Configuration |
| 221 | 225 | ||
| 222 | The following environment variables can be set to customize the behavior of | 226 | The following environment variables can be set to customize the behavior of |
| 223 | antigen. Make sure you set them *before* source-ing `antigen.zsh`. | 227 | antigen. Make sure you set them *before* source-ing `antigen.zsh`. |
| 224 | 228 | ||
| 225 | `ANTIGEN_DEFAULT_REPO_URL` — This is the default repository url that is | 229 | `ANTIGEN_DEFAULT_REPO_URL` — This is the default repository url that is |
| 226 | used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo, | 230 | used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo, |
| 227 | but you can set this to the fork url of your own fork. | 231 | but you can set this to the fork url of your own fork. |
| 228 | 232 | ||
| 229 | `ADOTDIR` — This directory is used to store all the repo clones, your | 233 | `ADOTDIR` — This directory is used to store all the repo clones, your |
| 230 | bundles, themes, caches and everything else antigen requires to run smoothly. | 234 | bundles, themes, caches and everything else antigen requires to run smoothly. |
| 231 | Defaults to `$HOME/.antigen`. | 235 | Defaults to `$HOME/.antigen`. |
| 232 | 236 | ||
| 233 | **Note**: `ANTIGEN_REPO_CACHE` & `ANTIGEN_BUNDLE_DIR` — These variables | 237 | **Note**: `ANTIGEN_REPO_CACHE` & `ANTIGEN_BUNDLE_DIR` — These variables |
| 234 | were used previously but are now removed. Please use `ADOTDIR` instead, as | 238 | were used previously but are now removed. Please use `ADOTDIR` instead, as |
| 235 | mentioned above. | 239 | mentioned above. |
| 236 | 240 | ||
| 237 | # Meta | 241 | # Meta |
| 238 | 242 | ||
| 239 | Project is licensed with the [MIT License][license]. To contribute, just fork, | 243 | Project is licensed with the [MIT License][license]. To contribute, just fork, |
| 240 | make changes and send a pull request. If its a rather long/complicated change, | 244 | make changes and send a pull request. If its a rather long/complicated change, |
| 241 | please consider opening an [issue][] first so we can discuss it out. | 245 | please consider opening an [issue][] first so we can discuss it out. |
| 242 | 246 | ||
| 243 | Any comments/suggestions/feedback welcome. Please join the discussion on the | 247 | Any comments/suggestions/feedback welcome. Please join the discussion on the |
| 244 | [reddit page][] of this project. Also, follow me on twitter, | 248 | [reddit page][] of this project. Also, follow me on twitter, |
| 245 | [@sharat87](twitter). | 249 | [@sharat87](twitter). |
| 246 | 250 | ||
| 247 | [Vundle]: https://github.com/gmarik/vundle | 251 | [Vundle]: https://github.com/gmarik/vundle |
| 248 | [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh | 252 | [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh |
| 249 | [issue]: https://github.com/sharat87/antigen/issues | 253 | [issue]: https://github.com/sharat87/antigen/issues |
| 250 | [license]: http://mit.sharats.me | 254 | [license]: http://mit.sharats.me |
| 251 | [reddit page]: http://www.reddit.com/r/commandline/comments/u4f26/antigen_a_plugin_manager_for_zsh_shell/ | 255 | [reddit page]: http://www.reddit.com/r/commandline/comments/u4f26/antigen_a_plugin_manager_for_zsh_shell/ |
| 252 | [twitter]: http://twitter.com/sharat87 | 256 | [twitter]: http://twitter.com/sharat87 |
| 253 | 257 |
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> | 5 | # <repo-url>, <plugin-location>, <bundle-type> |
| 6 | # FIXME: Is not kept local by zsh! | 6 | # FIXME: Is not kept local by zsh! |
| 7 | local _ANTIGEN_BUNDLE_RECORD="" | 7 | local _ANTIGEN_BUNDLE_RECORD="" |
| 8 | 8 | ||
| 9 | # Syntaxes | 9 | # Syntaxes |
| 10 | # antigen-bundle <url> [<loc>=/] | 10 | # antigen-bundle <url> [<loc>=/] |
| 11 | antigen-bundle () { | 11 | antigen-bundle () { |
| 12 | 12 | ||
| 13 | # Bundle spec arguments' default values. | 13 | # Bundle spec arguments' default values. |
| 14 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 14 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
| 15 | local loc=/ | 15 | local loc=/ |
| 16 | local btype=plugin | 16 | local btype=plugin |
| 17 | 17 | ||
| 18 | # Set spec values based on the positional arguments. | 18 | # Set spec values based on the positional arguments. |
| 19 | local position_args='url loc' | 19 | local position_args='url loc' |
| 20 | local i=1 | 20 | local i=1 |
| 21 | while ! [[ -z $1 || $1 == --*=* ]]; do | 21 | while ! [[ -z $1 || $1 == --*=* ]]; do |
| 22 | local arg_name="$(echo "$position_args" | cut -d\ -f$i)" | 22 | local arg_name="$(echo "$position_args" | cut -d\ -f$i)" |
| 23 | local arg_value="$1" | 23 | local arg_value="$1" |
| 24 | eval "local $arg_name='$arg_value'" | 24 | eval "local $arg_name='$arg_value'" |
| 25 | shift | 25 | shift |
| 26 | i=$(($i + 1)) | 26 | i=$(($i + 1)) |
| 27 | done | 27 | done |
| 28 | 28 | ||
| 29 | # Check if url is just the plugin name. Super short syntax. | 29 | # Check if url is just the plugin name. Super short syntax. |
| 30 | if [[ "$url" != */* ]]; then | 30 | if [[ "$url" != */* ]]; then |
| 31 | loc="plugins/$url" | 31 | loc="plugins/$url" |
| 32 | url="$ANTIGEN_DEFAULT_REPO_URL" | 32 | url="$ANTIGEN_DEFAULT_REPO_URL" |
| 33 | fi | 33 | fi |
| 34 | 34 | ||
| 35 | # Set spec values from keyword arguments, if any. The remaining arguments | 35 | # Set spec values from keyword arguments, if any. The remaining arguments |
| 36 | # are all assumed to be keyword arguments. | 36 | # are all assumed to be keyword arguments. |
| 37 | while [[ $1 == --*=* ]]; do | 37 | while [[ $1 == --*=* ]]; do |
| 38 | local arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" | 38 | local arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" |
| 39 | local arg_value="$(echo "$1" | cut -d= -f2)" | 39 | local arg_value="$(echo "$1" | cut -d= -f2)" |
| 40 | eval "local $arg_name='$arg_value'" | 40 | eval "local $arg_name='$arg_value'" |
| 41 | shift | 41 | shift |
| 42 | done | 42 | done |
| 43 | 43 | ||
| 44 | # Resolve the url. | 44 | # Resolve the url. |
| 45 | if [[ $url != git://* && $url != https://* && $url != /* ]]; then | 45 | if [[ $url != git://* && $url != https://* && $url != /* ]]; then |
| 46 | url="${url%.git}" | 46 | url="${url%.git}" |
| 47 | url="https://github.com/$url.git" | 47 | url="https://github.com/$url.git" |
| 48 | fi | 48 | fi |
| 49 | 49 | ||
| 50 | # Add it to the record. | 50 | # Add it to the record. |
| 51 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" | 51 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" |
| 52 | 52 | ||
| 53 | -antigen-ensure-repo "$url" | 53 | -antigen-ensure-repo "$url" |
| 54 | 54 | ||
| 55 | -antigen-load "$url" "$loc" "$btype" | 55 | -antigen-load "$url" "$loc" "$btype" |
| 56 | 56 | ||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | antigen-bundles () { | 59 | antigen-bundles () { |
| 60 | # Bulk add many bundles at one go. Empty lines and lines starting with a `#` | 60 | # Bulk add many bundles at one go. Empty lines and lines starting with a `#` |
| 61 | # are ignored. Everything else is given to `antigen-bundle` as is, no | 61 | # are ignored. Everything else is given to `antigen-bundle` as is, no |
| 62 | # quoting rules applied. | 62 | # quoting rules applied. |
| 63 | 63 | ||
| 64 | local line | 64 | local line |
| 65 | 65 | ||
| 66 | grep -v '^$\|^#' | while read line; do | 66 | grep -v '^$\|^#' | while read line; do |
| 67 | # Using `eval` so that we can use the shell-style quoting in each line | 67 | # Using `eval` so that we can use the shell-style quoting in each line |
| 68 | # piped to `antigen-bundles`. | 68 | # piped to `antigen-bundles`. |
| 69 | eval "antigen-bundle $line" | 69 | eval "antigen-bundle $line" |
| 70 | done | 70 | done |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | antigen-bundle-update () { | 73 | antigen-update () { |
| 74 | # Update your bundles, i.e., `git pull` in all the plugin repos. | 74 | # Update your bundles, i.e., `git pull` in all the plugin repos. |
| 75 | -antigen-echo-record | awk '{print $1}' | sort -u | while read url; do | 75 | -antigen-echo-record | awk '{print $1}' | sort -u | while read url; do |
| 76 | -antigen-ensure-repo --update "$url" | 76 | -antigen-ensure-repo --update "$url" |
| 77 | done | 77 | done |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | -antigen-get-clone-dir () { | 80 | -antigen-get-clone-dir () { |
| 81 | # Takes a repo url and gives out the path that this url needs to be cloned | 81 | # Takes a repo url and gives out the path that this url needs to be cloned |
| 82 | # to. Doesn't actually clone anything. | 82 | # to. Doesn't actually clone anything. |
| 83 | # TODO: Memoize? | 83 | # TODO: Memoize? |
| 84 | echo -n $ADOTDIR/repos/ | 84 | echo -n $ADOTDIR/repos/ |
| 85 | echo "$1" | sed \ | 85 | echo "$1" | sed \ |
| 86 | -e 's/\.git$//' \ | 86 | -e 's/\.git$//' \ |
| 87 | -e 's./.-SLASH-.g' \ | 87 | -e 's./.-SLASH-.g' \ |
| 88 | -e 's.:.-COLON-.g' | 88 | -e 's.:.-COLON-.g' |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | -antigen-get-clone-url () { | 91 | -antigen-get-clone-url () { |
| 92 | # Takes a repo's clone dir and gives out the repo's original url that was | 92 | # Takes a repo's clone dir and gives out the repo's original url that was |
| 93 | # used to create the given directory path. | 93 | # used to create the given directory path. |
| 94 | # TODO: Memoize? | 94 | # TODO: Memoize? |
| 95 | echo "$1" | sed \ | 95 | echo "$1" | sed \ |
| 96 | -e "s:^$ADOTDIR/repos/::" \ | 96 | -e "s:^$ADOTDIR/repos/::" \ |
| 97 | -e 's/$/.git/' \ | 97 | -e 's/$/.git/' \ |
| 98 | -e 's.-SLASH-./.g' \ | 98 | -e 's.-SLASH-./.g' \ |
| 99 | -e 's.-COLON-.:.g' | 99 | -e 's.-COLON-.:.g' |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | -antigen-ensure-repo () { | 102 | -antigen-ensure-repo () { |
| 103 | 103 | ||
| 104 | local update=false | 104 | local update=false |
| 105 | if [[ $1 == --update ]]; then | 105 | if [[ $1 == --update ]]; then |
| 106 | update=true | 106 | update=true |
| 107 | shift | 107 | shift |
| 108 | fi | 108 | fi |
| 109 | 109 | ||
| 110 | local url="$1" | 110 | local url="$1" |
| 111 | local clone_dir="$(-antigen-get-clone-dir $url)" | 111 | local clone_dir="$(-antigen-get-clone-dir $url)" |
| 112 | 112 | ||
| 113 | if [[ ! -d $clone_dir ]]; then | 113 | if [[ ! -d $clone_dir ]]; then |
| 114 | git clone "$url" "$clone_dir" | 114 | git clone "$url" "$clone_dir" |
| 115 | elif $update; then | 115 | elif $update; then |
| 116 | git --git-dir "$clone_dir/.git" pull | 116 | git --git-dir "$clone_dir/.git" pull |
| 117 | fi | 117 | fi |
| 118 | 118 | ||
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | -antigen-load () { | 121 | -antigen-load () { |
| 122 | 122 | ||
| 123 | local url="$1" | 123 | local url="$1" |
| 124 | local location="$(-antigen-get-clone-dir "$url")/$2" | 124 | local location="$(-antigen-get-clone-dir "$url")/$2" |
| 125 | local btype="$3" | 125 | local btype="$3" |
| 126 | 126 | ||
| 127 | if [[ $btype == theme ]]; then | 127 | if [[ $btype == theme ]]; then |
| 128 | 128 | ||
| 129 | # Of course, if its a theme, the location would point to the script | 129 | # Of course, if its a theme, the location would point to the script |
| 130 | # file. | 130 | # file. |
| 131 | source "$location" | 131 | source "$location" |
| 132 | 132 | ||
| 133 | else | 133 | else |
| 134 | 134 | ||
| 135 | # Source the plugin script | 135 | # Source the plugin script |
| 136 | # FIXME: I don't know. Looks very very ugly. Needs a better | 136 | # FIXME: I don't know. Looks very very ugly. Needs a better |
| 137 | # implementation once tests are ready. | 137 | # implementation once tests are ready. |
| 138 | local script_loc="$(ls "$location" | grep -m1 '.plugin.zsh$')" | 138 | local script_loc="$(ls "$location" | grep -m1 '.plugin.zsh$')" |
| 139 | if [[ -f $script_loc ]]; then | 139 | if [[ -f $script_loc ]]; then |
| 140 | # If we have a `*.plugin.zsh`, source it. | 140 | # If we have a `*.plugin.zsh`, source it. |
| 141 | source "$script_loc" | 141 | source "$script_loc" |
| 142 | elif [[ ! -z "$(ls "$location" | grep -m1 '.zsh$')" ]]; then | 142 | elif [[ ! -z "$(ls "$location" | grep -m1 '.zsh$')" ]]; then |
| 143 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` | 143 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` |
| 144 | # files. | 144 | # files. |
| 145 | for script ($location/*.zsh) source "$script" | 145 | for script ($location/*.zsh) source "$script" |
| 146 | fi | 146 | fi |
| 147 | 147 | ||
| 148 | # Add to $fpath, for completion(s) | 148 | # Add to $fpath, for completion(s) |
| 149 | fpath=($location $fpath) | 149 | fpath=($location $fpath) |
| 150 | 150 | ||
| 151 | fi | 151 | fi |
| 152 | 152 | ||
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | antigen-cleanup () { | 155 | antigen-cleanup () { |
| 156 | 156 | ||
| 157 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then | 157 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then |
| 158 | echo "You don't have any bundles." | 158 | echo "You don't have any bundles." |
| 159 | return 0 | 159 | return 0 |
| 160 | fi | 160 | fi |
| 161 | 161 | ||
| 162 | # Find directores in ADOTDIR/repos, that are not in the bundles record. | 162 | # Find directores in ADOTDIR/repos, that are not in the bundles record. |
| 163 | local unused_clones="$(comm -13 \ | 163 | local unused_clones="$(comm -13 \ |
| 164 | <(-antigen-echo-record | awk '{print $1}' | sort -u) \ | 164 | <(-antigen-echo-record | awk '{print $1}' | sort -u) \ |
| 165 | <(ls "$ADOTDIR/repos" | while read line; do | 165 | <(ls "$ADOTDIR/repos" | while read line; do |
| 166 | -antigen-get-clone-url "$line" | 166 | -antigen-get-clone-url "$line" |
| 167 | done))" | 167 | done))" |
| 168 | 168 | ||
| 169 | if [[ -z $unused_clones ]]; then | 169 | if [[ -z $unused_clones ]]; then |
| 170 | echo "You don't have any unidentified bundles." | 170 | echo "You don't have any unidentified bundles." |
| 171 | return 0 | 171 | return 0 |
| 172 | fi | 172 | fi |
| 173 | 173 | ||
| 174 | echo 'You have clones for the following repos, but are not used.' | 174 | echo 'You have clones for the following repos, but are not used.' |
| 175 | echo "$unused_clones" | sed 's/^/ /' | 175 | echo "$unused_clones" | sed 's/^/ /' |
| 176 | 176 | ||
| 177 | echo -n '\nDelete them all? [y/N] ' | 177 | echo -n '\nDelete them all? [y/N] ' |
| 178 | if read -q; then | 178 | if read -q; then |
| 179 | echo | 179 | echo |
| 180 | echo | 180 | echo |
| 181 | echo "$unused_clones" | while read url; do | 181 | echo "$unused_clones" | while read url; do |
| 182 | echo -n "Deleting clone for $url..." | 182 | echo -n "Deleting clone for $url..." |
| 183 | rm -rf "$(-antigen-get-clone-dir $url)" | 183 | rm -rf "$(-antigen-get-clone-dir $url)" |
| 184 | echo ' done.' | 184 | echo ' done.' |
| 185 | done | 185 | done |
| 186 | else | 186 | else |
| 187 | echo | 187 | echo |
| 188 | echo Nothing deleted. | 188 | echo Nothing deleted. |
| 189 | fi | 189 | fi |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | antigen-lib () { | 192 | antigen-lib () { |
| 193 | antigen-bundle --loc=lib | 193 | antigen-bundle --loc=lib |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | antigen-theme () { | 196 | antigen-theme () { |
| 197 | local name="${1:-robbyrussell}" | 197 | local name="${1:-robbyrussell}" |
| 198 | antigen-bundle --loc=themes/$name.zsh-theme --btype=theme | 198 | antigen-bundle --loc=themes/$name.zsh-theme --btype=theme |
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | antigen-apply () { | 201 | antigen-apply () { |
| 202 | # Initialize completion. | 202 | # Initialize completion. |
| 203 | # TODO: Only load completions if there are any changes to the bundle | 203 | # TODO: Only load completions if there are any changes to the bundle |
| 204 | # repositories. | 204 | # repositories. |
| 205 | compinit -i | 205 | compinit -i |
| 206 | } | 206 | } |
| 207 | 207 | ||
| 208 | antigen-list () { | 208 | antigen-list () { |
| 209 | # List all currently installed bundles | 209 | # List all currently installed bundles |
| 210 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then | 210 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then |
| 211 | echo "You don't have any bundles." >&2 | 211 | echo "You don't have any bundles." >&2 |
| 212 | return 1 | 212 | return 1 |
| 213 | else | 213 | else |
| 214 | -antigen-echo-record | 214 | -antigen-echo-record |
| 215 | fi | 215 | fi |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | # Echo the bundle specs as in the record. The first line is not echoed since it | 218 | # Echo the bundle specs as in the record. The first line is not echoed since it |
| 219 | # is a blank line. | 219 | # is a blank line. |
| 220 | -antigen-echo-record () { | 220 | -antigen-echo-record () { |
| 221 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' | 221 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' |
| 222 | } | 222 | } |
| 223 | 223 | ||
| 224 | -antigen-env-setup () { | 224 | -antigen-env-setup () { |
| 225 | # Pre-startup initializations | 225 | # Pre-startup initializations |
| 226 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 226 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
| 227 | https://github.com/robbyrussell/oh-my-zsh.git | 227 | https://github.com/robbyrussell/oh-my-zsh.git |
| 228 | -set-default ADOTDIR $HOME/.antigen | 228 | -set-default ADOTDIR $HOME/.antigen |
| 229 | 229 | ||
| 230 | # Load the compinit module | 230 | # Load the compinit module |
| 231 | autoload -U compinit | 231 | autoload -U compinit |
| 232 | 232 | ||
| 233 | # Without the following, `compdef` function is not defined. | 233 | # Without the following, `compdef` function is not defined. |
| 234 | compinit -i | 234 | compinit -i |
| 235 | } | 235 | } |
| 236 | 236 | ||
| 237 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is | 237 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is |
| 238 | # not already set. | 238 | # not already set. |
| 239 | -set-default () { | 239 | -set-default () { |
| 240 | local arg_name="$1" | 240 | local arg_name="$1" |
| 241 | local arg_value="$2" | 241 | local arg_value="$2" |
| 242 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 242 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | -antigen-env-setup | 245 | -antigen-env-setup |
| 246 | 246 |