Commit 911cc8cb5a3e2ca6b63388147bda2caf81bd0e5e

Authored by Shrikant Sharat
1 parent 9dc6310031

Use ADOTDIR as the path to `.antigen` directory.

The previously used two variables ANTIGEN_REPO_CACHE and ANTIGEN_BUNDLE_DIR are
now replaced by a single variable, ADOTDIR. Defaults to `$HOME/.antigen`.

Showing 2 changed files with 18 additions and 17 deletions Inline Diff

1 # Antigen 1 # Antigen
2 2
3 Antigen is a small set of functions that help you easily manage your shell (zsh) 3 Antigen is a small set of functions that help you easily manage your shell (zsh)
4 plugins, called bundles. The concept is pretty much the same as bundles in a 4 plugins, called bundles. The concept is pretty much the same as bundles in a
5 typical vim+pathogen setup. Antigen is to zsh, what [Vundle][] is to vim. 5 typical vim+pathogen setup. Antigen is to zsh, what [Vundle][] is to vim.
6 6
7 # 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. 35 # Tell antigen that you're done.
36 bundle-apply 36 bundle-apply
37 37
38 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
39 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
40 on this page. 40 on this page.
41 41
42 # Motivation 42 # Motivation
43 43
44 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
45 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
46 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
47 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
48 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
49 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.
50 50
51 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
52 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,
53 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
54 shell script expert (far from it). 54 shell script expert (far from it).
55 55
56 [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465 56 [1]: https://github.com/robbyrussell/oh-my-zsh/issues/465
57 [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377 57 [2]: https://github.com/robbyrussell/oh-my-zsh/issues/377
58 [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014 58 [3]: https://github.com/robbyrussell/oh-my-zsh/issues/1014
59 59
60 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
61 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
62 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
63 now and then. 63 now and then.
64 64
65 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
66 66
67 bundle-theme candy 67 bundle-theme candy
68 68
69 and your prompt is changed, just for this session of course. 69 and your prompt is changed, just for this session of course.
70 70
71 # Commands 71 # Commands
72 72
73 ## bundle 73 ## bundle
74 74
75 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
76 simplest usage follows the following syntax 76 simplest usage follows the following syntax
77 77
78 bundle <plugin-name> 78 bundle <plugin-name>
79 79
80 This will add the `plugins/<name>` directory from [robbyrussell's 80 This will add the `plugins/<name>` directory from [robbyrussell's
81 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`).
82 82
83 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`
84 command. 84 command.
85 85
86 bundle [<url> [<loc> [<name>]]] 86 bundle [<url> [<loc> [<name>]]]
87 87
88 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
89 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
90 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`
91 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
92 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
93 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
94 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
95 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
96 arguments. 96 arguments.
97 97
98 An example invocation would be 98 An example invocation would be
99 99
100 bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant 100 bundle https://github.com/robbyrussell/oh-my-zsh.git plugins/ant
101 101
102 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
103 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.
104 104
105 bundle robbyrussell/oh-my-zsh plugins/ant 105 bundle robbyrussell/oh-my-zsh plugins/ant
106 106
107 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
108 the `loc` without giving the first argument. 108 the `loc` without giving the first argument.
109 109
110 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
111 argument syntax, using which we can rewrite the above as 111 argument syntax, using which we can rewrite the above as
112 112
113 bundle --loc=plugins/ant 113 bundle --loc=plugins/ant
114 114
115 Which is the same as 115 Which is the same as
116 116
117 bundle ant 117 bundle ant
118 118
119 (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).
120 120
121 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
122 have positional arguments after starting keyword arguments. 122 have positional arguments after starting keyword arguments.
123 123
124 bundle robbyrussell/oh-my-zsh --loc=plugins/ant 124 bundle robbyrussell/oh-my-zsh --loc=plugins/ant
125 125
126 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
127 specified. The following is perfectly valid. 127 specified. The following is perfectly valid.
128 128
129 bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh --name=ant 129 bundle --loc=plugins/ant --url=robbyrussell/oh-my-zsh --name=ant
130 130
131 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
132 arguments but only as keyword arguments. 132 arguments but only as keyword arguments.
133 133
134 `load` &mdash; Set to `true` (default) or `false`. If this is set to `false`, 134 `load` &mdash; Set to `true` (default) or `false`. If this is set to `false`,
135 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
136 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
137 is ready to use, which is the default behavior. 137 is ready to use, which is the default behavior.
138 138
139 ## bundle-install 139 ## bundle-install
140 140
141 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
142 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
143 following syntax. 143 following syntax.
144 144
145 bundle-install [--update] [<plugin-spec>] 145 bundle-install [--update] [<plugin-spec>]
146 146
147 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
148 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
149 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
150 not already installed. 150 not already installed.
151 151
152 The other argument part illustrated above is the `<plugin-spec>`. Other than the 152 The other argument part illustrated above is the `<plugin-spec>`. Other than the
153 optional `--update` argument, everything else is considered as describing a 153 optional `--update` argument, everything else is considered as describing a
154 particular plugin to be installed. So, a command like 154 particular plugin to be installed. So, a command like
155 155
156 bundle-install <plugin-spec> 156 bundle-install <plugin-spec>
157 157
158 is **almost** equivalent to 158 is **almost** equivalent to
159 159
160 bundle <plugin-spec> 160 bundle <plugin-spec>
161 bundle-install 161 bundle-install
162 162
163 I say **almost** because in the former, *only* the said plugin is installed and 163 I say **almost** because in the former, *only* the said plugin is installed and
164 is usable immediately. This kind of invocation is supposed to be used directly 164 is usable immediately. This kind of invocation is supposed to be used directly
165 from the shell, not added to your `.zshrc`. The idea is to let you try out new 165 from the shell, not added to your `.zshrc`. The idea is to let you try out new
166 plugins you come across. For example, 166 plugins you come across. For example,
167 167
168 bundle-install lol 168 bundle-install lol
169 169
170 After that, you have the `lol` plugin ready to be used right there. You can try 170 After that, you have the `lol` plugin ready to be used right there. You can try
171 it out and if you like it, you can add the following to load it in every new 171 it out and if you like it, you can add the following to load it in every new
172 shell instance you open 172 shell instance you open
173 173
174 bundle lol 174 bundle lol
175 175
176 If you don't want it, the plugin will still stay installed, but won't be used. 176 If you don't want it, the plugin will still stay installed, but won't be used.
177 No harm done, but you can run `bundle-cleanup` to clean up such stray plugins 177 No harm done, but you can run `bundle-cleanup` to clean up such stray plugins
178 that you don't use. Documentation for that command further down. 178 that you don't use. Documentation for that command further down.
179 179
180 **Note** that the `<plugin-spec>` can be made of multiple number of arguments, 180 **Note** that the `<plugin-spec>` can be made of multiple number of arguments,
181 just like the `bundle` command can take multiple number of arguments to 181 just like the `bundle` command can take multiple number of arguments to
182 correctly describe the plugin. 182 correctly describe the plugin.
183 183
184 ## bundle-install! 184 ## bundle-install!
185 185
186 This is the same as running 186 This is the same as running
187 187
188 bundle-install --update 188 bundle-install --update
189 189
190 That is, it installs the recorded plugins, and updates them to the latest 190 That is, it installs the recorded plugins, and updates them to the latest
191 available versions. 191 available versions.
192 192
193 ## bundle-list 193 ## bundle-list
194 194
195 Use this command to list out the currently recorded plugins. *Note* that the 195 Use this command to list out the currently recorded plugins. *Note* that the
196 plugins listed by this command are not necessarily installed. They are just the 196 plugins listed by this command are not necessarily installed. They are just the
197 ones that have be recorded, probably with the `bundle` command. 197 ones that have be recorded, probably with the `bundle` command.
198 198
199 If you have done any on-spot temporary installation of some plugins with 199 If you have done any on-spot temporary installation of some plugins with
200 `bundle-install`, they will *not* be listed in the output of this command. 200 `bundle-install`, they will *not* be listed in the output of this command.
201 Record them with the `bundle` command for them to be listed in the output of 201 Record them with the `bundle` command for them to be listed in the output of
202 this command. 202 this command.
203 203
204 ## bundle-cleanup 204 ## bundle-cleanup
205 205
206 Used to clean up unused bundles. It takes no arguments. When this is run, it 206 Used to clean up unused bundles. It takes no arguments. When this is run, it
207 lists out the plugins that are installed but are not recorded with a `bundle` 207 lists out the plugins that are installed but are not recorded with a `bundle`
208 command, and will ask you if you want to delete them. 208 command, and will ask you if you want to delete them.
209 209
210 This command currently cannot run in a non-interactive mode. So it won't be very 210 This command currently cannot run in a non-interactive mode. So it won't be very
211 pleasant to use it in your `.zshrc`. 211 pleasant to use it in your `.zshrc`.
212 212
213 ## bundle-lib 213 ## bundle-lib
214 214
215 This currently exists only to make is possible to use oh-my-zsh's library, since 215 This currently exists only to make is possible to use oh-my-zsh's library, since
216 its organisation is different from that of plugins. If you want to load 216 its organisation is different from that of plugins. If you want to load
217 oh-my-zsh's library, which you very likely do, put a 217 oh-my-zsh's library, which you very likely do, put a
218 218
219 bundle-lib 219 bundle-lib
220 220
221 in your `.zshrc`, before any `bundle` declarations. It takes no arguments. 221 in your `.zshrc`, before any `bundle` declarations. It takes no arguments.
222 222
223 ## bundle-theme 223 ## bundle-theme
224 224
225 Used for switching the prompt theme. Invoke it with the name of the theme you 225 Used for switching the prompt theme. Invoke it with the name of the theme you
226 want to use. 226 want to use.
227 227
228 bundle-theme fox 228 bundle-theme fox
229 229
230 Currently, themes are pulled from robbyrussell's oh-my-zsh repo, but it will 230 Currently, themes are pulled from robbyrussell's oh-my-zsh repo, but it will
231 support getting themes from other repos as well in the future. 231 support getting themes from other repos as well in the future.
232 232
233 ## bundle-apply 233 ## bundle-apply
234 234
235 You have to add this command after defining all bundles you need, in your zshrc. 235 You have to add this command after defining all bundles you need, in your zshrc.
236 The completions defined by your bundles will be loaded at this step. 236 The completions defined by your bundles will be loaded at this step.
237 237
238 It is possible to load completions as and when a bundle is specified with the 238 It is possible to load completions as and when a bundle is specified with the
239 bundle command, in which case this command would not be necessary. But loading 239 bundle command, in which case this command would not be necessary. But loading
240 the completions is a time-consuming process and your shell will start noticeably 240 the completions is a time-consuming process and your shell will start noticeably
241 slow if you have a good number of bundle specifications. 241 slow if you have a good number of bundle specifications.
242 242
243 However, if you're a zsh expert and can suggest a way so that this would not be 243 However, if you're a zsh expert and can suggest a way so that this would not be
244 necessary, I am very interested in discussing it. Please open up an issue with 244 necessary, I am very interested in discussing it. Please open up an issue with
245 your details. Thanks. 245 your details. Thanks.
246 246
247 # Configuration 247 # Configuration
248 248
249 The following environment variables can be set to customize the behavior of 249 The following environment variables can be set to customize the behavior of
250 antigen. Make sure you set them *before* sourceing `antigen.zsh`. 250 antigen. Make sure you set them *before* sourceing `antigen.zsh`.
251 251
252 `ANTIGEN_DEFAULT_REPO_URL` &mdash; This is the default repository url that is 252 `ANTIGEN_DEFAULT_REPO_URL` &mdash; This is the default repository url that is
253 used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo, 253 used for `bundle` commands. The default value is robbyrussell's oh-my-zsh repo,
254 but you can set this to the fork url of your own fork. 254 but you can set this to the fork url of your own fork.
255 255
256 `ANTIGEN_REPO_CACHE` &mdash; This is where the cloned repositories are cached. 256 `ADOTDIR` &mdash; This directory is used to store all the repo clones, your
257 Defaults to `$HOME/.antigen/cache` 257 bundles, themes, caches and everything else antigen requires to run smoothly.
258 Defaults to `$HOME/.antigen`.
258 259
259 `ANTIGEN_BUNDLE_DIR` &mdash; This is where the plugins are installed and sourced 260 **Note**: `ANTIGEN_REPO_CACHE` & `ANTIGEN_BUNDLE_DIR` &mdash; These variables
260 from. Defaults to `$HOME/.antigen/bundles` 261 were used previously but are now removed. Please use `ADOTDIR` instead, as
262 mentioned above.
261 263
262 # Meta 264 # Meta
263 265
264 Please note that I built this over night and should be considered very alpha. 266 Please note that I built this over night and should be considered very alpha.
265 However, I am using it full time now on my work machine. 267 However, I am using it full time now on my work machine.
266 268
267 Project is licensed with the MIT License. To contribute, just fork, make changes 269 Project is licensed with the MIT License. To contribute, just fork, make changes
268 and send a pull request. If its a rather long/complicated change, please 270 and send a pull request. If its a rather long/complicated change, please
269 consider opening an [issue][] first so we can discuss it out. 271 consider opening an [issue][] first so we can discuss it out.
270 272
271 Any comments/suggestions/feedback welcome. Please join the discussion on the 273 Any comments/suggestions/feedback welcome. Please join the discussion on the
272 [reddit page][] of this project. 274 [reddit page][] of this project.
273 275
274 [Vundle]: https://github.com/gmarik/vundle 276 [Vundle]: https://github.com/gmarik/vundle
275 [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh 277 [oh-my-zsh]: https://github.com/robbyrussell/oh-my-zsh
276 [issue]: https://github.com/sharat87/antigen/issues 278 [issue]: https://github.com/sharat87/antigen/issues
277 [reddit page]: http://www.reddit.com/r/commandline/comments/u4f26/antigen_a_plugin_manager_for_zsh_shell/ 279 [reddit page]: http://www.reddit.com/r/commandline/comments/u4f26/antigen_a_plugin_manager_for_zsh_shell/
278 280
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 _ANTIGEN_BUNDLE_RECORD="" 7 local _ANTIGEN_BUNDLE_RECORD=""
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 local arg_name="$(echo "$position_args" | cut -d\ -f$i)" 23 local arg_name="$(echo "$position_args" | cut -d\ -f$i)"
24 local arg_value="$1" 24 local 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 local arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" 39 local arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')"
40 local arg_value="$(echo "$1" | cut -d= -f2)" 40 local 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="$ADOTDIR/repos/$(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 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$name $url $loc $clone_dir" 63 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\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 local update=false 73 local update=false
74 if [[ $1 == --update ]]; then 74 if [[ $1 == --update ]]; then
75 update=true 75 update=true
76 shift 76 shift
77 fi 77 fi
78 78
79 mkdir -p "$ANTIGEN_BUNDLE_DIR" 79 mkdir -p "$ADOTDIR/bundles"
80 80
81 local handled_repos="" 81 local handled_repos=""
82 local install_bundles="" 82 local install_bundles=""
83 83
84 if [[ $# != 0 ]]; then 84 if [[ $# != 0 ]]; then
85 # Record and install just the given plugin here and now. 85 # Record and install just the given plugin here and now.
86 bundle "$@" 86 bundle "$@"
87 install_bundles="$(-bundle-echo-record | tail -1)" 87 install_bundles="$(-bundle-echo-record | tail -1)"
88 else 88 else
89 # Install all the plugins, previously recorded. 89 # Install all the plugins, previously recorded.
90 install_bundles="$(-bundle-echo-record)" 90 install_bundles="$(-bundle-echo-record)"
91 fi 91 fi
92 92
93 # If the above `if` is directly piped to the below `while`, the contents 93 # If the above `if` is directly piped to the below `while`, the contents
94 # inside the `if` construct are run in a new subshell, so changes to the 94 # inside the `if` construct are run in a new subshell, so changes to the
95 # `$_ANTIGEN_BUNDLE_RECORD` variable are lost after the `if` construct 95 # `$_ANTIGEN_BUNDLE_RECORD` variable are lost after the `if` construct
96 # finishes. So, we need the temporary `$install_bundles` variable. 96 # finishes. So, we need the temporary `$install_bundles` variable.
97 echo "$install_bundles" | while read spec; do 97 echo "$install_bundles" | while read spec; do
98 98
99 local name="$(echo "$spec" | awk '{print $1}')" 99 local name="$(echo "$spec" | awk '{print $1}')"
100 local url="$(echo "$spec" | awk '{print $2}')" 100 local url="$(echo "$spec" | awk '{print $2}')"
101 local loc="$(echo "$spec" | awk '{print $3}')" 101 local loc="$(echo "$spec" | awk '{print $3}')"
102 local clone_dir="$(echo "$spec" | awk '{print $4}')" 102 local clone_dir="$(echo "$spec" | awk '{print $4}')"
103 103
104 if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then 104 if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then
105 if [[ ! -d $clone_dir ]]; then 105 if [[ ! -d $clone_dir ]]; then
106 git clone "$url" "$clone_dir" 106 git clone "$url" "$clone_dir"
107 elif $update; then 107 elif $update; then
108 git --git-dir "$clone_dir/.git" pull 108 git --git-dir "$clone_dir/.git" pull
109 fi 109 fi
110 110
111 handled_repos="$handled_repos\n$url" 111 handled_repos="$handled_repos\n$url"
112 fi 112 fi
113 113
114 if [[ $name != *.theme ]]; then 114 if [[ $name != *.theme ]]; then
115 echo Installing $name 115 echo Installing $name
116 local bundle_dest="$ANTIGEN_BUNDLE_DIR/$name" 116 local bundle_dest="$ADOTDIR/bundles/$name"
117 test -e "$bundle_dest" && rm -rf "$bundle_dest" 117 test -e "$bundle_dest" && rm -rf "$bundle_dest"
118 ln -s "$clone_dir/$loc" "$bundle_dest" 118 ln -s "$clone_dir/$loc" "$bundle_dest"
119 else 119 else
120 mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" 120 mkdir -p "$ADOTDIR/bundles/$name"
121 cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" 121 cp "$clone_dir/$loc" "$ADOTDIR/bundles/$name"
122 fi 122 fi
123 123
124 bundle-load "$name" 124 bundle-load "$name"
125 125
126 done 126 done
127 127
128 # Initialize completions after installing 128 # Initialize completions after installing
129 bundle-apply 129 bundle-apply
130 130
131 } 131 }
132 132
133 bundle-install! () { 133 bundle-install! () {
134 bundle-install --update 134 bundle-install --update
135 } 135 }
136 136
137 bundle-cleanup () { 137 bundle-cleanup () {
138 138
139 if [[ ! -d "$ANTIGEN_BUNDLE_DIR" || \ 139 if [[ ! -d "$ADOTDIR/bundles" || \
140 "$(ls "$ANTIGEN_BUNDLE_DIR/" | wc -l)" == 0 ]]; then 140 "$(ls "$ADOTDIR/bundles/" | wc -l)" == 0 ]]; then
141 echo "You don't have any bundles." 141 echo "You don't have any bundles."
142 return 0 142 return 0
143 fi 143 fi
144 144
145 # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. 145 # Find directores in ADOTDIR/bundles, that are not in the bundles record.
146 local unidentified_bundles="$(comm -13 \ 146 local unidentified_bundles="$(comm -13 \
147 <(-bundle-echo-record | awk '{print $1}' | sort) \ 147 <(-bundle-echo-record | awk '{print $1}' | sort) \
148 <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" 148 <(ls -1 "$ADOTDIR/bundles"))"
149 149
150 if [[ -z $unidentified_bundles ]]; then 150 if [[ -z $unidentified_bundles ]]; then
151 echo "You don't have any unidentified bundles." 151 echo "You don't have any unidentified bundles."
152 return 0 152 return 0
153 fi 153 fi
154 154
155 echo The following bundles are not recorded: 155 echo The following bundles are not recorded:
156 echo "$unidentified_bundles" | sed 's/^/ /' 156 echo "$unidentified_bundles" | sed 's/^/ /'
157 157
158 echo -n '\nDelete them all? [y/N] ' 158 echo -n '\nDelete them all? [y/N] '
159 if read -q; then 159 if read -q; then
160 echo 160 echo
161 echo 161 echo
162 echo "$unidentified_bundles" | while read name; do 162 echo "$unidentified_bundles" | while read name; do
163 echo -n Deleting $name... 163 echo -n Deleting $name...
164 rm -rf "$ANTIGEN_BUNDLE_DIR/$name" 164 rm -rf "$ADOTDIR/bundles/$name"
165 echo ' done.' 165 echo ' done.'
166 done 166 done
167 else 167 else
168 echo 168 echo
169 echo Nothing deleted. 169 echo Nothing deleted.
170 fi 170 fi
171 } 171 }
172 172
173 bundle-load () { 173 bundle-load () {
174 174
175 local name="$1" 175 local name="$1"
176 local bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" 176 local bundle_dir="$ADOTDIR/bundles/$name"
177 177
178 # Source the plugin script 178 # Source the plugin script
179 local script_loc="$bundle_dir/$name.plugin.zsh" 179 local script_loc="$bundle_dir/$name.plugin.zsh"
180 if [[ -f $script_loc ]]; then 180 if [[ -f $script_loc ]]; then
181 source "$script_loc" 181 source "$script_loc"
182 fi 182 fi
183 183
184 # If the name of the plugin ends with `.lib`, all the *.zsh files in it are 184 # If the name of the plugin ends with `.lib`, all the *.zsh files in it are
185 # sourced. This is kind of a hack to source the libraries of oh-my-zsh. 185 # sourced. This is kind of a hack to source the libraries of oh-my-zsh.
186 if [[ $name == *.lib ]]; then 186 if [[ $name == *.lib ]]; then
187 # FIXME: This throws an error if no files match the given glob pattern. 187 # FIXME: This throws an error if no files match the given glob pattern.
188 for lib ($bundle_dir/*.zsh) source $lib 188 for lib ($bundle_dir/*.zsh) source $lib
189 fi 189 fi
190 190
191 # If the name ends with `.theme`, it is handled as if it were a zsh-theme 191 # If the name ends with `.theme`, it is handled as if it were a zsh-theme
192 # plugin. 192 # plugin.
193 if [[ $name == *.theme ]]; then 193 if [[ $name == *.theme ]]; then
194 local theme_file="$bundle_dir/${name%.theme}.zsh-theme" 194 local theme_file="$bundle_dir/${name%.theme}.zsh-theme"
195 test -f "$theme_file" && source "$theme_file" 195 test -f "$theme_file" && source "$theme_file"
196 fi 196 fi
197 197
198 # Add to $fpath, for completion(s) 198 # Add to $fpath, for completion(s)
199 fpath=($bundle_dir $fpath) 199 fpath=($bundle_dir $fpath)
200 200
201 } 201 }
202 202
203 bundle-lib () { 203 bundle-lib () {
204 bundle --name=oh-my-zsh.lib --loc=lib 204 bundle --name=oh-my-zsh.lib --loc=lib
205 } 205 }
206 206
207 bundle-theme () { 207 bundle-theme () {
208 local url="$ANTIGEN_DEFAULT_REPO_URL" 208 local url="$ANTIGEN_DEFAULT_REPO_URL"
209 local name="${1:-robbyrussell}" 209 local name="${1:-robbyrussell}"
210 bundle-install "$url" --name=$name.theme --loc=themes/$name.zsh-theme 210 bundle-install "$url" --name=$name.theme --loc=themes/$name.zsh-theme
211 } 211 }
212 212
213 bundle-apply () { 213 bundle-apply () {
214 # Initialize completion. 214 # Initialize completion.
215 compinit -i 215 compinit -i
216 } 216 }
217 217
218 bundle-list () { 218 bundle-list () {
219 # List all currently installed bundles 219 # List all currently installed bundles
220 if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then 220 if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then
221 echo "You don't have any bundles." >&2 221 echo "You don't have any bundles." >&2
222 return 1 222 return 1
223 else 223 else
224 -bundle-echo-record | awk '{print $1 " " $2 " " $3}' 224 -bundle-echo-record | awk '{print $1 " " $2 " " $3}'
225 fi 225 fi
226 } 226 }
227 227
228 # Does what it says. 228 # Does what it says.
229 -bundle-echo-record () { 229 -bundle-echo-record () {
230 echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' 230 echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p'
231 } 231 }
232 232
233 -bundle-env-setup () { 233 -bundle-env-setup () {
234 # Pre-startup initializations 234 # Pre-startup initializations
235 -set-default ANTIGEN_DEFAULT_REPO_URL \ 235 -set-default ANTIGEN_DEFAULT_REPO_URL \
236 https://github.com/robbyrussell/oh-my-zsh.git 236 https://github.com/robbyrussell/oh-my-zsh.git
237 -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache 237 -set-default ADOTDIR $HOME/.antigen
238 -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles
239 238
240 # Load the compinit module 239 # Load the compinit module
241 autoload -U compinit 240 autoload -U compinit
242 241
243 # Without the following, `compdef` function is not defined. 242 # Without the following, `compdef` function is not defined.
244 compinit -i 243 compinit -i
245 } 244 }
246 245
247 # Same as `export $1=$2`, but will only happen if the name specified by `$1` is 246 # Same as `export $1=$2`, but will only happen if the name specified by `$1` is
248 # not already set. 247 # not already set.
249 -set-default () { 248 -set-default () {
250 local arg_name="$1" 249 local arg_name="$1"
251 local arg_value="$2" 250 local arg_value="$2"
252 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" 251 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'"
253 } 252 }
254 253
255 -bundle-env-setup 254 -bundle-env-setup
256 255