Commit 1af74ea9edde7f3cec1f63068dc4f5aad2dcad68
1 parent
f554ec3587
Load completions after bundles are loaded.
bundle-init is now renamed to bundle-apply and is to called after all bundle specifications are given. Also added notes in the README file. The reason is the compinit function needs to be run after adding all the required directories to `fpath`. The only reliable and performant way to do it would be to explicitly call a function that does it after specifying all the bundles.
Showing 2 changed files with 18 additions and 2 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 | # Quick Usage | 7 | # Quick Usage |
8 | 8 | ||
9 | First, clone this repo, probably as a submodule if you have your dotfiles in a | 9 | First, clone this repo, probably as a submodule if you have your dotfiles in a |
10 | git repo, | 10 | git repo, |
11 | 11 | ||
12 | git clone https://github.com/sharat87/antigen.git | 12 | git clone https://github.com/sharat87/antigen.git |
13 | 13 | ||
14 | The usage should be very familiar to you if you use Vundle. A typical `.zshrc` | 14 | The usage should be very familiar to you if you use Vundle. A typical `.zshrc` |
15 | might look like this | 15 | might look like this |
16 | 16 | ||
17 | source /path-to-antigen-clone/antigen.zsh | 17 | source /path-to-antigen-clone/antigen.zsh |
18 | 18 | ||
19 | # Load the oh-my-zsh's library. | 19 | # Load the oh-my-zsh's library. |
20 | bundle-lib | 20 | bundle-lib |
21 | 21 | ||
22 | # Bundles from the default repo (robbyrussell's oh-my-zsh). | 22 | # Bundles from the default repo (robbyrussell's oh-my-zsh). |
23 | bundle git | 23 | bundle git |
24 | bundle heroku | 24 | bundle heroku |
25 | bundle pip | 25 | bundle pip |
26 | bundle lein | 26 | bundle lein |
27 | bundle command-not-found | 27 | bundle command-not-found |
28 | 28 | ||
29 | # Syntax highlighting bundle. | 29 | # Syntax highlighting bundle. |
30 | bundle zsh-users/zsh-syntax-highlighting | 30 | bundle zsh-users/zsh-syntax-highlighting |
31 | 31 | ||
32 | # Load the theme. | 32 | # Load the theme. |
33 | bundle-theme robbyrussell | 33 | bundle-theme robbyrussell |
34 | 34 | ||
35 | # Tell antigen that you're done. | ||
36 | bundle-apply | ||
37 | |||
35 | Open your zsh with this zshrc and run `bundle-install` and you should be ready | 38 | Open your zsh with this zshrc and run `bundle-install` and you should be ready |
36 | to roll. The complete syntax for the `bundle` command is discussed further down | 39 | to roll. The complete syntax for the `bundle` command is discussed further down |
37 | on this page. | 40 | on this page. |
38 | 41 | ||
39 | # Motivation | 42 | # Motivation |
40 | 43 | ||
41 | If you use zsh and [oh-my-zsh][], you know that having many different plugins | 44 | If you use zsh and [oh-my-zsh][], you know that having many different plugins |
42 | that are developed by many different authors in a single (sub)repo is not a very | 45 | that are developed by many different authors in a single (sub)repo is not a very |
43 | easy to maintain. There are some really fantastic plugins and utilities in | 46 | easy to maintain. There are some really fantastic plugins and utilities in |
44 | oh-my-zsh, but having them all in a single repo doesn't really scale well. And I | 47 | oh-my-zsh, but having them all in a single repo doesn't really scale well. And I |
45 | admire robbyrussell's efforts for reviewing and mergine the gigantic number of | 48 | admire robbyrussell's efforts for reviewing and mergine the gigantic number of |
46 | pull requests the project gets. It needs a better way of plugin management. | 49 | pull requests the project gets. It needs a better way of plugin management. |
47 | 50 | ||
48 | This was discussed on [a][1] [few][2] [issues][3], but it doesn't look like | 51 | This was discussed on [a][1] [few][2] [issues][3], but it doesn't look like |
49 | there was any progress made. So, I'm trying to start this off with antigen, | 52 | there was any progress made. So, I'm trying to start this off with antigen, |
50 | hoping to better this situation. Please note that I'm by no means a zsh or any | 53 | hoping to better this situation. Please note that I'm by no means a zsh or any |
51 | shell script expert (far from it). | 54 | shell script expert (far from it). |
52 | 55 | ||
53 | [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465 | 56 | [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465 |
54 | [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377 | 57 | [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377 |
55 | [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014 | 58 | [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014 |
56 | 59 | ||
57 | Inspired by vundle, antigen can pull oh-my-zsh style plugins from various github | 60 | Inspired by vundle, antigen can pull oh-my-zsh style plugins from various github |
58 | repositories. You are not limited to use plugins from the oh-my-zsh repository | 61 | repositories. You are not limited to use plugins from the oh-my-zsh repository |
59 | only and you don't need to maintain your own fork and pull from upstream every | 62 | only and you don't need to maintain your own fork and pull from upstream every |
60 | now and then. | 63 | now and then. |
61 | 64 | ||
62 | Antigen also lets you switch the prompt theme with one command, just like that | 65 | Antigen also lets you switch the prompt theme with one command, just like that |
63 | 66 | ||
64 | bundle-theme candy | 67 | bundle-theme candy |
65 | 68 | ||
66 | and your prompt is changed, just for this session of course. | 69 | and your prompt is changed, just for this session of course. |
67 | 70 | ||
68 | # Commands | 71 | # Commands |
69 | 72 | ||
70 | ## bundle | 73 | ## bundle |
71 | 74 | ||
72 | This is the command you use to tell antigen that you want to use a plugin. The | 75 | This is the command you use to tell antigen that you want to use a plugin. The |
73 | simplest usage follows the following syntax | 76 | simplest usage follows the following syntax |
74 | 77 | ||
75 | bundle <plugin-name> | 78 | bundle <plugin-name> |
76 | 79 | ||
77 | This will add the `plugins/<name>` directory from [robbyrussell's | 80 | This will add the `plugins/<name>` directory from [robbyrussell's |
78 | oh-my-zsh][oh-my-zsh] (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`). | 81 | oh-my-zsh][oh-my-zsh] (can be changed by setting `ANTIGEN_DEFAULT_REPO_URL`). |
79 | 82 | ||
80 | However, the above is just syntax sugar for the real syntax of the `bundle` | 83 | However, the above is just syntax sugar for the real syntax of the `bundle` |
81 | command. | 84 | command. |
82 | 85 | ||
83 | bundle [<url> [<loc> [<name>]]] | 86 | bundle [<url> [<loc> [<name>]]] |
84 | 87 | ||
85 | where `<url>` is the repository url and it defaults to [robbyrussell's | 88 | where `<url>` is the repository url and it defaults to [robbyrussell's |
86 | oh-my-zsh][oh-my-zsh] repo. `<loc>` is the path under this repository which has | 89 | oh-my-zsh][oh-my-zsh] repo. `<loc>` is the path under this repository which has |
87 | the zsh plugin. This is typically the directory that contains a `*.plugin.zsh` | 90 | the zsh plugin. This is typically the directory that contains a `*.plugin.zsh` |
88 | file, but it could contain a completion file too. `<loc>` defaults to `/`, which | 91 | file, but it could contain a completion file too. `<loc>` defaults to `/`, which |
89 | indicates the repository itself is a plugin. `<name>` is the name with which | 92 | indicates the repository itself is a plugin. `<name>` is the name with which |
90 | this plugin will be identified. This plugin will be installed in the bundles | 93 | this plugin will be identified. This plugin will be installed in the bundles |
91 | directory with this name used as the directory name. If the `<name>` is not | 94 | directory with this name used as the directory name. If the `<name>` is not |
92 | given, antigen tries to make an intelligent guess based on the other given | 95 | given, antigen tries to make an intelligent guess based on the other given |
93 | arguments. | 96 | arguments. |
94 | 97 | ||
95 | An example invocation would be | 98 | An example invocation would be |
96 | 99 | ||
97 | bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant | 100 | bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant |
98 | 101 | ||
99 | This would install the ant plugin (with `<name>` as `ant`) from robbyrussell's | 102 | This would install the ant plugin (with `<name>` as `ant`) from robbyrussell's |
100 | oh-my-zsh repo. Of course, github url's can be shortened. | 103 | oh-my-zsh repo. Of course, github url's can be shortened. |
101 | 104 | ||
102 | bundle robbyrussell/oh-my-zsh plugins/ant | 105 | bundle robbyrussell/oh-my-zsh plugins/ant |
103 | 106 | ||
104 | And since this is the default, even that isn't necessary. But we can't specify | 107 | And since this is the default, even that isn't necessary. But we can't specify |
105 | the `loc` without giving the first argument. | 108 | the `loc` without giving the first argument. |
106 | 109 | ||
107 | For this and a few other reasons, `bundle` also supports a simple keyword | 110 | For this and a few other reasons, `bundle` also supports a simple keyword |
108 | argument syntax, using which we can rewrite the above as | 111 | argument syntax, using which we can rewrite the above as |
109 | 112 | ||
110 | bundle --loc=plugins/ant | 113 | bundle --loc=plugins/ant |
111 | 114 | ||
112 | Which is the same as | 115 | Which is the same as |
113 | 116 | ||
114 | bundle ant | 117 | bundle ant |
115 | 118 | ||
116 | (In the short syntax sugar introduced at the start of this section). | 119 | (In the short syntax sugar introduced at the start of this section). |
117 | 120 | ||
118 | Note that you can mix and match positional and keyword arguments. But you can't | 121 | Note that you can mix and match positional and keyword arguments. But you can't |
119 | have positional arguments after starting keyword arguments. | 122 | have positional arguments after starting keyword arguments. |
120 | 123 | ||
121 | bundle robbyrussell/oh-my-zsh --loc=plugins/ant | 124 | bundle robbyrussell/oh-my-zsh --loc=plugins/ant |
122 | 125 | ||
123 | And keyword arguments don't care about the order in which the arguments are | 126 | And keyword arguments don't care about the order in which the arguments are |
124 | specified. The following is perfectly valid. | 127 | specified. The following is perfectly valid. |
125 | 128 | ||
126 | bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh --name=ant | 129 | bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh --name=ant |
127 | 130 | ||
128 | In addition to the above discussed arguments, `bundle` also takes the following | 131 | In addition to the above discussed arguments, `bundle` also takes the following |
129 | arguments but only as keyword arguments. | 132 | arguments but only as keyword arguments. |
130 | 133 | ||
131 | `load` — Set to `true` (default) or `false`. If this is set to `false`, | 134 | `load` — Set to `true` (default) or `false`. If this is set to `false`, |
132 | the plugin specified is only recorded, may be for future use. It is not loaded | 135 | the plugin specified is only recorded, may be for future use. It is not loaded |
133 | into the environment. But with `true`, the plugin is immediately sourced and | 136 | into the environment. But with `true`, the plugin is immediately sourced and |
134 | is ready to use, which is the default behavior. | 137 | is ready to use, which is the default behavior. |
135 | 138 | ||
136 | ## bundle-install | 139 | ## bundle-install |
137 | 140 | ||
138 | This is something you might not want to put in your `.zshrc`. Instead, run it to | 141 | This is something you might not want to put in your `.zshrc`. Instead, run it to |
139 | install all the recorded bundles, using the `bundle` command. It has the | 142 | install all the recorded bundles, using the `bundle` command. It has the |
140 | following syntax. | 143 | following syntax. |
141 | 144 | ||
142 | bundle-install [--update] | 145 | bundle-install [--update] |
143 | 146 | ||
144 | The optional `--update` argument can be given to update all your plugins from | 147 | The optional `--update` argument can be given to update all your plugins from |
145 | the server. By default, `bundle-install` does *not* check for updates on the | 148 | the server. By default, `bundle-install` does *not* check for updates on the |
146 | plugins. It just installs them, if there is a cached copy available and if its | 149 | plugins. It just installs them, if there is a cached copy available and if its |
147 | not already installed. | 150 | not already installed. |
148 | 151 | ||
149 | ## bundle-install! | 152 | ## bundle-install! |
150 | 153 | ||
151 | This is the same as running | 154 | This is the same as running |
152 | 155 | ||
153 | bundle-install --update | 156 | bundle-install --update |
154 | 157 | ||
155 | That is, it installs the recorded plugins, and updates them to the latest | 158 | That is, it installs the recorded plugins, and updates them to the latest |
156 | available versions. | 159 | available versions. |
157 | 160 | ||
158 | ## bundle-cleanup | 161 | ## bundle-cleanup |
159 | 162 | ||
160 | Used to clean up unused bundles. It takes no arguments. When this is run, it | 163 | Used to clean up unused bundles. It takes no arguments. When this is run, it |
161 | lists out the plugins that are installed but are not recorded with a `bundle` | 164 | lists out the plugins that are installed but are not recorded with a `bundle` |
162 | command, and will ask you if you want to delete them. | 165 | command, and will ask you if you want to delete them. |
163 | 166 | ||
164 | This command currently cannot run in a non-interactive mode. So it won't be very | 167 | This command currently cannot run in a non-interactive mode. So it won't be very |
165 | pleasant to use it in your `.zshrc`. | 168 | pleasant to use it in your `.zshrc`. |
166 | 169 | ||
167 | ## bundle-lib | 170 | ## bundle-lib |
168 | 171 | ||
169 | This currently exists only to make is possible to use oh-my-zsh's library, since | 172 | This currently exists only to make is possible to use oh-my-zsh's library, since |
170 | its organisation is different from that of plugins. If you want to load | 173 | its organisation is different from that of plugins. If you want to load |
171 | oh-my-zsh's library, which you very likely do, put a | 174 | oh-my-zsh's library, which you very likely do, put a |
172 | 175 | ||
173 | bundle-lib | 176 | bundle-lib |
174 | 177 | ||
175 | in your `.zshrc`, before any `bundle` declarations. It takes no arguments. | 178 | in your `.zshrc`, before any `bundle` declarations. It takes no arguments. |
176 | 179 | ||
177 | ## bundle-theme | 180 | ## bundle-theme |
178 | 181 | ||
179 | Used for switching the prompt theme. Invoke it with the name of the theme you | 182 | Used for switching the prompt theme. Invoke it with the name of the theme you |
180 | want to use. | 183 | want to use. |
181 | 184 | ||
182 | bundle-theme fox | 185 | bundle-theme fox |
183 | 186 | ||
184 | Currently, themes are pulled from robbyrussell's oh-my-zsh repo, but it will | 187 | Currently, themes are pulled from robbyrussell's oh-my-zsh repo, but it will |
185 | support getting themes from other repos as well in the future. | 188 | support getting themes from other repos as well in the future. |
186 | 189 | ||
190 | ## bundle-apply | ||
191 | |||
192 | You have to add this command after defining all bundles you need, in your zshrc. | ||
193 | The completions defined by your bundles will be loaded at this step. | ||
194 | |||
195 | It is possible to load completions as and when a bundle is specified with the | ||
196 | bundle command, in which case this command would not be necessary. But loading | ||
197 | the completions is a time-consuming process and your shell will start noticeably | ||
198 | slow if you have a good number of bundle specifications. | ||
199 | |||
200 | However, if you're a zsh expert and can suggest a way so that this would not be | ||
201 | necessary, I am very interested in discussing it. Please open up an issue with | ||
202 | your details. Thanks. | ||
203 | |||
187 | # Configuration | 204 | # Configuration |
188 | 205 | ||
189 | The following environment variables can be set to customize the behavior of | 206 | The following environment variables can be set to customize the behavior of |
190 | antigen. Make sure you set them *before* sourceing `antigen.zsh`. | 207 | antigen. Make sure you set them *before* sourceing `antigen.zsh`. |
191 | 208 | ||
192 | `ANTIGEN_DEFAULT_REPO_URL` — This is the default repository url that is | 209 | `ANTIGEN_DEFAULT_REPO_URL` — This is the default repository url that is |
193 | used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo, | 210 | used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo, |
194 | but you can set this to the fork url of your own fork. | 211 | but you can set this to the fork url of your own fork. |
195 | 212 | ||
196 | `ANTIGEN_REPO_CACHE` — This is where the cloned repositories are cached. | 213 | `ANTIGEN_REPO_CACHE` — This is where the cloned repositories are cached. |
197 | Defaults to `$HOME/.antigen/cache` | 214 | Defaults to `$HOME/.antigen/cache` |
198 | 215 | ||
199 | `ANTIGEN_BUNDLE_DIR` — This is where the plugins are installed and sourced | 216 | `ANTIGEN_BUNDLE_DIR` — This is where the plugins are installed and sourced |
200 | from. Defaults to `$HOME/.antigen/bundles` | 217 | from. Defaults to `$HOME/.antigen/bundles` |
201 | 218 | ||
202 | # Meta | 219 | # Meta |
203 | 220 | ||
204 | Please note that I built this over night and should be considered very alpha. | 221 | Please note that I built this over night and should be considered very alpha. |
205 | However, I am using it full time now on my work machine. | 222 | However, I am using it full time now on my work machine. |
206 | 223 | ||
207 | Project is licensed with the MIT License. To contribute, just fork, make changes | 224 | Project is licensed with the MIT License. To contribute, just fork, make changes |
208 | and send a pull request. If its a rather long/complicated change, please | 225 | and send a pull request. If its a rather long/complicated change, please |
209 | consider opening an [issue][] first so we can discuss it out. | 226 | consider opening an [issue][] first so we can discuss it out. |
210 | 227 | ||
211 | Any comments/suggestions/feedback welcome. Please join the discussion on the | 228 | Any comments/suggestions/feedback welcome. Please join the discussion on the |
212 | [reddit page][] of this project. | 229 | [reddit page][] of this project. |
213 | 230 | ||
214 | [Vundle]: https://github.com/gmarik/vundle | 231 | [Vundle]: https://github.com/gmarik/vundle |
215 | [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh | 232 | [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh |
216 | [issue]: https://github.com/sharat87/antigen/issues | 233 | [issue]: https://github.com/sharat87/antigen/issues |
217 | [reddit page]: http://www.reddit.com/r/commandline/comments/u4f26/antigen_a_plugin_manager_for_zsh_shell/ | 234 | [reddit page]: http://www.reddit.com/r/commandline/comments/u4f26/antigen_a_plugin_manager_for_zsh_shell/ |
218 | 235 |
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 | # <bundle-name>, <repo-url>, <plugin-location>, <repo-local-clone-dir> | 5 | # <bundle-name>, <repo-url>, <plugin-location>, <repo-local-clone-dir> |
6 | # FIXME: Is not kept local by zsh! | 6 | # FIXME: Is not kept local by zsh! |
7 | local bundles="" | 7 | local bundles="" |
8 | 8 | ||
9 | # Syntaxes | 9 | # Syntaxes |
10 | # bundle <url> [<loc>=/] [<name>] | 10 | # bundle <url> [<loc>=/] [<name>] |
11 | bundle () { | 11 | 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 name= | 16 | local name= |
17 | local load=true | 17 | local load=true |
18 | 18 | ||
19 | # Set spec values based on the positional arguments. | 19 | # Set spec values based on the positional arguments. |
20 | local position_args='url loc name' | 20 | local position_args='url loc name' |
21 | local i=1 | 21 | local i=1 |
22 | while ! [[ -z $1 || $1 == --*=* ]]; do | 22 | while ! [[ -z $1 || $1 == --*=* ]]; do |
23 | arg_name="$(echo "$position_args" | cut -d\ -f$i)" | 23 | arg_name="$(echo "$position_args" | cut -d\ -f$i)" |
24 | arg_value="$1" | 24 | arg_value="$1" |
25 | eval "local $arg_name='$arg_value'" | 25 | eval "local $arg_name='$arg_value'" |
26 | shift | 26 | shift |
27 | i=$(($i + 1)) | 27 | i=$(($i + 1)) |
28 | done | 28 | done |
29 | 29 | ||
30 | # Check if url is just the plugin name. Super short syntax. | 30 | # Check if url is just the plugin name. Super short syntax. |
31 | if [[ "$url" != */* ]]; then | 31 | if [[ "$url" != */* ]]; then |
32 | loc="plugins/$url" | 32 | loc="plugins/$url" |
33 | url="$ANTIGEN_DEFAULT_REPO_URL" | 33 | url="$ANTIGEN_DEFAULT_REPO_URL" |
34 | fi | 34 | fi |
35 | 35 | ||
36 | # Set spec values from keyword arguments, if any. The remaining arguments | 36 | # Set spec values from keyword arguments, if any. The remaining arguments |
37 | # are all assumed to be keyword arguments. | 37 | # are all assumed to be keyword arguments. |
38 | while [[ $1 == --*=* ]]; do | 38 | while [[ $1 == --*=* ]]; do |
39 | arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" | 39 | arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" |
40 | arg_value="$(echo "$1" | cut -d= -f2)" | 40 | arg_value="$(echo "$1" | cut -d= -f2)" |
41 | eval "local $arg_name='$arg_value'" | 41 | eval "local $arg_name='$arg_value'" |
42 | shift | 42 | shift |
43 | done | 43 | done |
44 | 44 | ||
45 | # Resolve the url. | 45 | # Resolve the url. |
46 | if [[ $url != git://* && $url != https://* ]]; then | 46 | if [[ $url != git://* && $url != https://* ]]; then |
47 | url="${url%.git}" | 47 | url="${url%.git}" |
48 | name="$(basename "$url")" | 48 | name="$(basename "$url")" |
49 | url="https://github.com/$url.git" | 49 | url="https://github.com/$url.git" |
50 | fi | 50 | fi |
51 | 51 | ||
52 | # Plugin's repo will be cloned here. | 52 | # Plugin's repo will be cloned here. |
53 | local clone_dir="$ANTIGEN_REPO_CACHE/$(echo "$url" \ | 53 | local clone_dir="$ANTIGEN_REPO_CACHE/$(echo "$url" \ |
54 | | sed -e 's/\.git$//' -e 's./.-SLASH-.g' -e 's.:.-COLON-.g')" | 54 | | sed -e 's/\.git$//' -e 's./.-SLASH-.g' -e 's.:.-COLON-.g')" |
55 | 55 | ||
56 | # Make an intelligent guess about the name of the plugin, if not already | 56 | # Make an intelligent guess about the name of the plugin, if not already |
57 | # done or is explicitly specified. | 57 | # done or is explicitly specified. |
58 | if [[ -z $name ]]; then | 58 | if [[ -z $name ]]; then |
59 | name="$(basename $url/$loc)" | 59 | name="$(basename $url/$loc)" |
60 | fi | 60 | fi |
61 | 61 | ||
62 | # Add it to the record. | 62 | # Add it to the record. |
63 | bundles="$bundles\n$name $url $loc $clone_dir" | 63 | bundles="$bundles\n$name $url $loc $clone_dir" |
64 | 64 | ||
65 | # Load it, unless specified otherwise. | 65 | # Load it, unless specified otherwise. |
66 | if $load; then | 66 | if $load; then |
67 | bundle-load "$name" | 67 | bundle-load "$name" |
68 | fi | 68 | fi |
69 | } | 69 | } |
70 | 70 | ||
71 | bundle-install () { | 71 | bundle-install () { |
72 | 72 | ||
73 | if [[ $1 == --update ]]; then | 73 | if [[ $1 == --update ]]; then |
74 | local update=true | 74 | local update=true |
75 | else | 75 | else |
76 | local update=false | 76 | local update=false |
77 | fi | 77 | fi |
78 | 78 | ||
79 | mkdir -p "$ANTIGEN_BUNDLE_DIR" | 79 | mkdir -p "$ANTIGEN_BUNDLE_DIR" |
80 | 80 | ||
81 | local handled_repos="" | 81 | local handled_repos="" |
82 | 82 | ||
83 | echo-non-empty "$bundles" | while read spec; do | 83 | echo-non-empty "$bundles" | while read spec; do |
84 | echo "-> $spec" | 84 | echo "-> $spec" |
85 | 85 | ||
86 | local name="$(echo "$spec" | awk '{print $1}')" | 86 | local name="$(echo "$spec" | awk '{print $1}')" |
87 | local url="$(echo "$spec" | awk '{print $2}')" | 87 | local url="$(echo "$spec" | awk '{print $2}')" |
88 | local loc="$(echo "$spec" | awk '{print $3}')" | 88 | local loc="$(echo "$spec" | awk '{print $3}')" |
89 | local clone_dir="$(echo "$spec" | awk '{print $4}')" | 89 | local clone_dir="$(echo "$spec" | awk '{print $4}')" |
90 | 90 | ||
91 | if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then | 91 | if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then |
92 | if [[ ! -d $clone_dir ]]; then | 92 | if [[ ! -d $clone_dir ]]; then |
93 | git clone "$url" "$clone_dir" | 93 | git clone "$url" "$clone_dir" |
94 | elif $update; then | 94 | elif $update; then |
95 | git --git-dir "$clone_dir/.git" pull | 95 | git --git-dir "$clone_dir/.git" pull |
96 | fi | 96 | fi |
97 | 97 | ||
98 | handled_repos="$handled_repos\n$url" | 98 | handled_repos="$handled_repos\n$url" |
99 | fi | 99 | fi |
100 | 100 | ||
101 | if [[ $name != *.theme ]]; then | 101 | if [[ $name != *.theme ]]; then |
102 | echo Installing $name | 102 | echo Installing $name |
103 | local bundle_dest="$ANTIGEN_BUNDLE_DIR/$name" | 103 | local bundle_dest="$ANTIGEN_BUNDLE_DIR/$name" |
104 | test -e "$bundle_dest" && rm -rf "$bundle_dest" | 104 | test -e "$bundle_dest" && rm -rf "$bundle_dest" |
105 | ln -s "$clone_dir/$loc" "$bundle_dest" | 105 | ln -s "$clone_dir/$loc" "$bundle_dest" |
106 | else | 106 | else |
107 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" | 107 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" |
108 | cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" | 108 | cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" |
109 | fi | 109 | fi |
110 | 110 | ||
111 | bundle-load "$name" | 111 | bundle-load "$name" |
112 | 112 | ||
113 | done | 113 | done |
114 | 114 | ||
115 | } | 115 | } |
116 | 116 | ||
117 | bundle-install! () { | 117 | bundle-install! () { |
118 | bundle-install --update | 118 | bundle-install --update |
119 | } | 119 | } |
120 | 120 | ||
121 | bundle-cleanup () { | 121 | bundle-cleanup () { |
122 | 122 | ||
123 | # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. | 123 | # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. |
124 | local unidentified_bundles="$(comm -13 \ | 124 | local unidentified_bundles="$(comm -13 \ |
125 | <(echo-non-empty "$bundles" | awk '{print $1}' | sort) \ | 125 | <(echo-non-empty "$bundles" | awk '{print $1}' | sort) \ |
126 | <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" | 126 | <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" |
127 | 127 | ||
128 | if [[ -z $unidentified_bundles ]]; then | 128 | if [[ -z $unidentified_bundles ]]; then |
129 | echo "You don't have any unidentified bundles." | 129 | echo "You don't have any unidentified bundles." |
130 | return 0 | 130 | return 0 |
131 | fi | 131 | fi |
132 | 132 | ||
133 | echo The following bundles are not recorded: | 133 | echo The following bundles are not recorded: |
134 | echo "$unidentified_bundles" | sed 's/^/ /' | 134 | echo "$unidentified_bundles" | sed 's/^/ /' |
135 | 135 | ||
136 | echo -n '\nDelete them all? [y/N] ' | 136 | echo -n '\nDelete them all? [y/N] ' |
137 | if read -q; then | 137 | if read -q; then |
138 | echo | 138 | echo |
139 | echo | 139 | echo |
140 | echo "$unidentified_bundles" | while read name; do | 140 | echo "$unidentified_bundles" | while read name; do |
141 | echo -n Deleting $name... | 141 | echo -n Deleting $name... |
142 | rm -rf "$ANTIGEN_BUNDLE_DIR/$name" | 142 | rm -rf "$ANTIGEN_BUNDLE_DIR/$name" |
143 | echo ' done.' | 143 | echo ' done.' |
144 | done | 144 | done |
145 | else | 145 | else |
146 | echo | 146 | echo |
147 | echo Nothing deleted. | 147 | echo Nothing deleted. |
148 | fi | 148 | fi |
149 | } | 149 | } |
150 | 150 | ||
151 | bundle-load () { | 151 | bundle-load () { |
152 | if [[ $1 == --init ]]; then | 152 | if [[ $1 == --init ]]; then |
153 | do_init=true | 153 | do_init=true |
154 | shift | 154 | shift |
155 | else | 155 | else |
156 | do_init=false | 156 | do_init=false |
157 | fi | 157 | fi |
158 | 158 | ||
159 | name="$1" | 159 | name="$1" |
160 | bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" | 160 | bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" |
161 | 161 | ||
162 | # Source the plugin script | 162 | # Source the plugin script |
163 | script_loc="$bundle_dir/$name.plugin.zsh" | 163 | script_loc="$bundle_dir/$name.plugin.zsh" |
164 | if [[ -f $script_loc ]]; then | 164 | if [[ -f $script_loc ]]; then |
165 | source "$script_loc" | 165 | source "$script_loc" |
166 | fi | 166 | fi |
167 | 167 | ||
168 | # If the name of the plugin ends with `.lib`, all the *.zsh files in it are | 168 | # If the name of the plugin ends with `.lib`, all the *.zsh files in it are |
169 | # sourced. This is kind of a hack to source the libraries of oh-my-zsh. | 169 | # sourced. This is kind of a hack to source the libraries of oh-my-zsh. |
170 | if [[ $name == *.lib ]]; then | 170 | if [[ $name == *.lib ]]; then |
171 | # FIXME: This throws an error if no files match the given glob pattern. | 171 | # FIXME: This throws an error if no files match the given glob pattern. |
172 | for lib ($bundle_dir/*.zsh) source $lib | 172 | for lib ($bundle_dir/*.zsh) source $lib |
173 | fi | 173 | fi |
174 | 174 | ||
175 | # If the name ends with `.theme`, it is handled as if it were a zsh-theme | 175 | # If the name ends with `.theme`, it is handled as if it were a zsh-theme |
176 | # plugin. | 176 | # plugin. |
177 | if [[ $name == *.theme ]]; then | 177 | if [[ $name == *.theme ]]; then |
178 | source "$bundle_dir/${name%.theme}.zsh-theme" | 178 | source "$bundle_dir/${name%.theme}.zsh-theme" |
179 | fi | 179 | fi |
180 | 180 | ||
181 | # Add to $fpath, for completion(s) | 181 | # Add to $fpath, for completion(s) |
182 | fpath=($bundle_dir $fpath) | 182 | fpath=($bundle_dir $fpath) |
183 | 183 | ||
184 | if $do_init; then | 184 | if $do_init; then |
185 | bundle-init | 185 | bundle-init |
186 | fi | 186 | fi |
187 | } | 187 | } |
188 | 188 | ||
189 | bundle-lib () { | 189 | bundle-lib () { |
190 | bundle --name=oh-my-zsh.lib --loc=lib | 190 | bundle --name=oh-my-zsh.lib --loc=lib |
191 | } | 191 | } |
192 | 192 | ||
193 | bundle-theme () { | 193 | bundle-theme () { |
194 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 194 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
195 | local name="${1:-robbyrussell}" | 195 | local name="${1:-robbyrussell}" |
196 | bundle "$url" --name=$name.theme --loc=themes/$name.zsh-theme | 196 | bundle "$url" --name=$name.theme --loc=themes/$name.zsh-theme |
197 | } | 197 | } |
198 | 198 | ||
199 | bundle-init () { | 199 | bundle-apply () { |
200 | # Initialize completion. | 200 | # Initialize completion. |
201 | if ! type compinit &>/dev/null; then | 201 | if ! type compinit &>/dev/null; then |
202 | autoload -U compinit | 202 | autoload -U compinit |
203 | fi | 203 | fi |
204 | compinit -i | 204 | compinit -i |
205 | } | 205 | } |
206 | 206 | ||
207 | # Does what it says. | 207 | # Does what it says. |
208 | echo-non-empty () { | 208 | echo-non-empty () { |
209 | echo "$@" | while read line; do | 209 | echo "$@" | while read line; do |
210 | [[ $line != "" ]] && echo $line | 210 | [[ $line != "" ]] && echo $line |
211 | done | 211 | done |
212 | } | 212 | } |
213 | 213 | ||
214 | -bundle-env-setup () { | 214 | -bundle-env-setup () { |
215 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 215 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
216 | https://github.com/robbyrussell/oh-my-zsh.git | 216 | https://github.com/robbyrussell/oh-my-zsh.git |
217 | -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache | 217 | -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache |
218 | -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles | 218 | -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles |
219 | } | 219 | } |
220 | 220 | ||
221 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is | 221 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is |
222 | # not already set. | 222 | # not already set. |
223 | -set-default () { | 223 | -set-default () { |
224 | arg_name="$1" | 224 | arg_name="$1" |
225 | arg_value="$2" | 225 | arg_value="$2" |
226 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 226 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
227 | } | 227 | } |
228 | 228 | ||
229 | -bundle-env-setup | 229 | -bundle-env-setup |
230 | bundle-init | ||
231 | 230 |