Commit 013216d53fb751f697a428b3794f7aaecc7066b2

Authored by Shrikant Sharat

Merge branch 'master' of https://github.com/Tarrasch/antigen

Conflicts:
	antigen.zsh

Showing 2 changed files Inline Diff

1 #!/bin/zsh 1 #!/bin/zsh
2 2
3 # Each line in this string has the following entries separated by a space 3 # Each line in this string has the following entries separated by a space
4 # character. 4 # character.
5 # <repo-url>, <plugin-location>, <bundle-type>, <has-local-clone> 5 # <repo-url>, <plugin-location>, <bundle-type>, <has-local-clone>
6 # FIXME: Is not kept local by zsh! 6 # FIXME: Is not kept local by zsh!
7 local _ANTIGEN_BUNDLE_RECORD="" 7 local _ANTIGEN_BUNDLE_RECORD=""
8 8
9 # Syntaxes 9 # Syntaxes
10 # antigen-bundle <url> [<loc>=/] 10 # antigen-bundle <url> [<loc>=/]
11 # Keyword only arguments: 11 # Keyword only arguments:
12 # branch - The branch of the repo to use for this bundle. 12 # branch - The branch of the repo to use for this bundle.
13 antigen-bundle () { 13 antigen-bundle () {
14 14
15 # Bundle spec arguments' default values. 15 # Bundle spec arguments' default values.
16 local url="$ANTIGEN_DEFAULT_REPO_URL" 16 local url="$ANTIGEN_DEFAULT_REPO_URL"
17 local loc=/ 17 local loc=/
18 local branch= 18 local branch=
19 local no_local_clone=false 19 local no_local_clone=false
20 local btype=plugin 20 local btype=plugin
21 21
22 # Set spec values based on the positional arguments. 22 # Set spec values based on the positional arguments.
23 local position_args 23 local position_args
24 position_args=(url loc) 24 position_args=(url loc)
25 local i=1 25 local i=1
26 while ! [[ -z $1 || $1 == --* ]]; do 26 while ! [[ -z $1 || $1 == --* ]]; do
27 local arg_name="${position_args[$i]}" 27 local arg_name="${position_args[$i]}"
28 local arg_value="$1" 28 local arg_value="$1"
29 eval "local $arg_name='$arg_value'" 29 eval "local $arg_name='$arg_value'"
30 shift 30 shift
31 i=$(($i + 1)) 31 i=$(($i + 1))
32 done 32 done
33 33
34 # Set spec values from keyword arguments, if any. The remaining arguments 34 # Set spec values from keyword arguments, if any. The remaining arguments
35 # are all assumed to be keyword arguments. 35 # are all assumed to be keyword arguments.
36 while [[ $1 == --* ]]; do 36 while [[ $1 == --* ]]; do
37 # Remove the `--` at the start. 37 # Remove the `--` at the start.
38 local arg="${1#--}" 38 local arg="${1#--}"
39 39
40 if [[ $arg != *=* ]]; then 40 if [[ $arg != *=* ]]; then
41 arg="$arg=true" 41 arg="$arg=true"
42 fi 42 fi
43 43
44 # Get the name of the arg and replace the `-`'s to `_`'s. 44 # Get the name of the arg and replace the `-`'s to `_`'s.
45 local arg_name="${${arg%\=*}//-/_}" 45 local arg_name="${${arg%\=*}//-/_}"
46 46
47 # Get the value of the arg. 47 # Get the value of the arg.
48 local arg_value="${arg#*\=}" 48 local arg_value="${arg#*\=}"
49 49
50 eval "local $arg_name='$arg_value'" 50 eval "local $arg_name='$arg_value'"
51 shift 51 shift
52 done 52 done
53 53
54 # Check if url is just the plugin name. Super short syntax. 54 # Check if url is just the plugin name. Super short syntax.
55 if [[ "$url" != */* ]]; then 55 if [[ "$url" != */* ]]; then
56 loc="plugins/$url" 56 loc="plugins/$url"
57 url="$ANTIGEN_DEFAULT_REPO_URL" 57 url="$ANTIGEN_DEFAULT_REPO_URL"
58 fi 58 fi
59 59
60 # Resolve the url. 60 # Resolve the url.
61 url="$(-antigen-resolve-bundle-url "$url")" 61 url="$(-antigen-resolve-bundle-url "$url")"
62 62
63 # Add the branch information to the url. 63 # Add the branch information to the url.
64 if [[ ! -z $branch ]]; then 64 if [[ ! -z $branch ]]; then
65 url="$url|$branch" 65 url="$url|$branch"
66 fi 66 fi
67 67
68 # The `make_local_clone` variable better represents whether there should be 68 # The `make_local_clone` variable better represents whether there should be
69 # a local clone made. For cloning to be avoided, firstly, the `$url` should 69 # a local clone made. For cloning to be avoided, firstly, the `$url` should
70 # be an absolute local path and `$branch` should be empty. In addition to 70 # be an absolute local path and `$branch` should be empty. In addition to
71 # these two conditions, either the `--no-local-clone` option should be 71 # these two conditions, either the `--no-local-clone` option should be
72 # given, or `$url` should not a git repo. 72 # given, or `$url` should not a git repo.
73 local make_local_clone=true 73 local make_local_clone=true
74 if [[ $url == /* && -z $branch \ 74 if [[ $url == /* && -z $branch \
75 && ( $no_local_clone == true || ! -d $url/.git ) ]]; then 75 && ( $no_local_clone == true || ! -d $url/.git ) ]]; then
76 make_local_clone=false 76 make_local_clone=false
77 fi 77 fi
78 78
79 # Add it to the record. 79 # Add it to the record.
80 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" 80 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype"
81 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD $make_local_clone" 81 _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD $make_local_clone"
82 82
83 # Ensure a clone exists for this repo, if needed. 83 # Ensure a clone exists for this repo, if needed.
84 if $make_local_clone; then 84 if $make_local_clone; then
85 -antigen-ensure-repo "$url" 85 -antigen-ensure-repo "$url"
86 fi 86 fi
87 87
88 # Load the plugin. 88 # Load the plugin.
89 -antigen-load "$url" "$loc" "$btype" "$make_local_clone" 89 -antigen-load "$url" "$loc" "$btype" "$make_local_clone"
90 90
91 } 91 }
92 92
93 -antigen-resolve-bundle-url () { 93 -antigen-resolve-bundle-url () {
94 # Given an acceptable short/full form of a bundle's repo url, this function 94 # Given an acceptable short/full form of a bundle's repo url, this function
95 # echoes the full form of the repo's clone url. 95 # echoes the full form of the repo's clone url.
96 96
97 local url="$1" 97 local url="$1"
98 98
99 # Expand short github url syntax: `username/reponame`. 99 # Expand short github url syntax: `username/reponame`.
100 if [[ $url != git://* && \ 100 if [[ $url != git://* && \
101 $url != https://* && \ 101 $url != https://* && \
102 $url != /* && \ 102 $url != /* && \
103 $url != git@github.com:*/* 103 $url != git@github.com:*/*
104 ]]; then 104 ]]; then
105 url="https://github.com/${url%.git}.git" 105 url="https://github.com/${url%.git}.git"
106 fi 106 fi
107 107
108 echo "$url" 108 echo "$url"
109 } 109 }
110 110
111 antigen-bundles () { 111 antigen-bundles () {
112 # Bulk add many bundles at one go. Empty lines and lines starting with a `#` 112 # Bulk add many bundles at one go. Empty lines and lines starting with a `#`
113 # are ignored. Everything else is given to `antigen-bundle` as is, no 113 # are ignored. Everything else is given to `antigen-bundle` as is, no
114 # quoting rules applied. 114 # quoting rules applied.
115 115
116 local line 116 local line
117 117
118 grep -v '^\s*$\|^#' | while read line; do 118 grep -v '^\s*$\|^#' | while read line; do
119 # Using `eval` so that we can use the shell-style quoting in each line 119 # Using `eval` so that we can use the shell-style quoting in each line
120 # piped to `antigen-bundles`. 120 # piped to `antigen-bundles`.
121 eval "antigen-bundle $line" 121 eval "antigen-bundle $line"
122 done 122 done
123 } 123 }
124 124
125 antigen-update () { 125 antigen-update () {
126 # Update your bundles, i.e., `git pull` in all the plugin repos. 126 # Update your bundles, i.e., `git pull` in all the plugin repos.
127 -antigen-echo-record \ 127 -antigen-echo-record \
128 | awk '{print $1}' \ 128 | awk '{print $1}' \
129 | sort -u \ 129 | sort -u \
130 | while read url; do 130 | while read url; do
131 echo "**** Pulling $url" 131 echo "**** Pulling $url"
132 -antigen-ensure-repo --update --verbose "$url" 132 -antigen-ensure-repo --update --verbose "$url"
133 echo 133 echo
134 done 134 done
135 } 135 }
136 136
137 -antigen-get-clone-dir () { 137 -antigen-get-clone-dir () {
138 # Takes a repo url and gives out the path that this url needs to be cloned 138 # Takes a repo url and gives out the path that this url needs to be cloned
139 # to. Doesn't actually clone anything. 139 # to. Doesn't actually clone anything.
140 # TODO: Memoize? 140 # TODO: Memoize?
141 141
142 # The url given. 142 # The url given.
143 local url="$1" 143 local url="$1"
144 144
145 # Echo the full path to the clone directory. 145 # Echo the full path to the clone directory.
146 echo -n $ADOTDIR/repos/ 146 echo -n $ADOTDIR/repos/
147 echo "$url" | sed \ 147 echo "$url" | sed \
148 -e 's./.-SLASH-.g' \ 148 -e 's./.-SLASH-.g' \
149 -e 's.:.-COLON-.g' \ 149 -e 's.:.-COLON-.g' \
150 -e 's.|.-PIPE-.g' 150 -e 's.|.-PIPE-.g'
151 } 151 }
152 152
153 -antigen-get-clone-url () { 153 -antigen-get-clone-url () {
154 # Takes a repo's clone dir and gives out the repo's original url that was 154 # Takes a repo's clone dir and gives out the repo's original url that was
155 # used to create the given directory path. 155 # used to create the given directory path.
156 # TODO: Memoize? 156 # TODO: Memoize?
157 echo "$1" | sed \ 157 echo "$1" | sed \
158 -e "s:^$ADOTDIR/repos/::" \ 158 -e "s:^$ADOTDIR/repos/::" \
159 -e 's.-SLASH-./.g' \ 159 -e 's.-SLASH-./.g' \
160 -e 's.-COLON-.:.g' \ 160 -e 's.-COLON-.:.g' \
161 -e 's.-PIPE-.|.g' 161 -e 's.-PIPE-.|.g'
162 } 162 }
163 163
164 -antigen-ensure-repo () { 164 -antigen-ensure-repo () {
165 165
166 # Ensure that a clone exists for the given repo url and branch. If the first 166 # Ensure that a clone exists for the given repo url and branch. If the first
167 # argument is `--update` and if a clone already exists for the given repo 167 # argument is `--update` and if a clone already exists for the given repo
168 # and branch, it is pull-ed, i.e., updated. 168 # and branch, it is pull-ed, i.e., updated.
169 169
170 # Argument defaults. 170 # Argument defaults.
171 # Check if we have to update. 171 # Check if we have to update.
172 local update=false 172 local update=false
173 # Verbose output. 173 # Verbose output.
174 local verbose=false 174 local verbose=false
175 175
176 # Load any boolean arguments specified. 176 # Load any boolean arguments specified.
177 while [[ $1 == --* ]]; do 177 while [[ $1 == --* ]]; do
178 eval "local '${1#--}=true'" 178 eval "local '${1#--}=true'"
179 shift 179 shift
180 done 180 done
181 181
182 # Get the clone's directory as per the given repo url and branch. 182 # Get the clone's directory as per the given repo url and branch.
183 local url="$1" 183 local url="$1"
184 local clone_dir="$(-antigen-get-clone-dir $url)" 184 local clone_dir="$(-antigen-get-clone-dir $url)"
185 185
186 # A temporary function wrapping the `git` command with repeated arguments. 186 # A temporary function wrapping the `git` command with repeated arguments.
187 --plugin-git () { 187 --plugin-git () {
188 eval git --git-dir=$clone_dir/.git --work-tree=$clone_dir "$@" 188 eval git --git-dir=$clone_dir/.git --work-tree=$clone_dir "$@"
189 } 189 }
190 190
191 # Clone if it doesn't already exist. 191 # Clone if it doesn't already exist.
192 if [[ ! -d $clone_dir ]]; then 192 if [[ ! -d $clone_dir ]]; then
193 git clone "${url%|*}" "$clone_dir" 193 git clone "${url%|*}" "$clone_dir"
194 elif $update; then 194 elif $update; then
195 # Save current revision. 195 # Save current revision.
196 local old_rev="$(--plugin-git rev-parse HEAD)" 196 local old_rev="$(--plugin-git rev-parse HEAD)"
197 # Pull changes if update requested. 197 # Pull changes if update requested.
198 --plugin-git pull 198 --plugin-git pull
199 # Get the new revision. 199 # Get the new revision.
200 local new_rev="$(--plugin-git rev-parse HEAD)" 200 local new_rev="$(--plugin-git rev-parse HEAD)"
201 fi
202
203 # If its a specific branch that we want, checkout that branch.
204 if [[ $url == *\|* ]]; then
201 fi 205 local current_branch=${$(--plugin-git symbolic-ref HEAD)##refs/heads/}
202 206 local requested_branch="${url#*|}"
203 # If its a specific branch that we want, checkout that branch. 207 # Only do the checkout when we are not already on the branch
204 if [[ $url == *\|* ]]; then 208 [[ $requested_branch != $current_branch ]] &&
205 --plugin-git checkout "${url#*|}" 209 --plugin-git checkout $requested_branch
206 fi 210 fi
207 211
208 if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then 212 if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then
209 echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. 213 echo Updated from ${old_rev:0:7} to ${new_rev:0:7}.
210 if $verbose; then 214 if $verbose; then
211 --plugin-git log --oneline --reverse --no-merges --stat '@{1}..' 215 --plugin-git log --oneline --reverse --no-merges --stat '@{1}..'
212 fi 216 fi
213 fi 217 fi
214 218
215 # Remove the temporary git wrapper function. 219 # Remove the temporary git wrapper function.
216 unfunction -- --plugin-git 220 unfunction -- --plugin-git
217 221
218 } 222 }
219 223
220 -antigen-load () { 224 -antigen-load () {
221 225
222 local url="$1" 226 local url="$1"
223 local loc="$2" 227 local loc="$2"
224 local btype="$3" 228 local btype="$3"
225 local make_local_clone="$4" 229 local make_local_clone="$4"
226 230
227 # The full location where the plugin is located. 231 # The full location where the plugin is located.
228 local location 232 local location
229 if $make_local_clone; then 233 if $make_local_clone; then
230 location="$(-antigen-get-clone-dir "$url")/$loc" 234 location="$(-antigen-get-clone-dir "$url")/$loc"
231 else 235 else
232 location="$url" 236 location="$url"
233 fi 237 fi
234 238
235 if [[ $btype == theme ]]; then 239 if [[ $btype == theme ]]; then
236 240
237 # Of course, if its a theme, the location would point to the script 241 # Of course, if its a theme, the location would point to the script
238 # file. 242 # file.
239 source "$location" 243 source "$location"
240 244
241 else 245 else
242 246
243 # Source the plugin script. 247 # Source the plugin script.
244 # FIXME: I don't know. Looks very very ugly. Needs a better 248 # FIXME: I don't know. Looks very very ugly. Needs a better
245 # implementation once tests are ready. 249 # implementation once tests are ready.
246 local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" 250 local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')"
247 251
248 if [[ -f $script_loc ]]; then 252 if [[ -f $script_loc ]]; then
249 # If we have a `*.plugin.zsh`, source it. 253 # If we have a `*.plugin.zsh`, source it.
250 source "$script_loc" 254 source "$script_loc"
251 255
252 elif [[ ! -z "$(ls "$location" | grep -m1 '\.zsh$')" ]]; then 256 elif [[ ! -z "$(ls "$location" | grep -m1 '\.zsh$')" ]]; then
253 # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` 257 # If there is no `*.plugin.zsh` file, source *all* the `*.zsh`
254 # files. 258 # files.
255 for script ($location/*.zsh(N)) source "$script" 259 for script ($location/*.zsh(N)) source "$script"
256 260
257 elif [[ ! -z "$(ls "$location" | grep -m1 '\.sh$')" ]]; then 261 elif [[ ! -z "$(ls "$location" | grep -m1 '\.sh$')" ]]; then
258 # If there are no `*.zsh` files either, we look for and source any 262 # If there are no `*.zsh` files either, we look for and source any
259 # `*.sh` files instead. 263 # `*.sh` files instead.
260 for script ($location/*.sh(N)) source "$script" 264 for script ($location/*.sh(N)) source "$script"
261 265
262 fi 266 fi
263 267
264 # Add to $fpath, for completion(s). 268 # Add to $fpath, for completion(s).
265 fpath=($location $fpath) 269 fpath=($location $fpath)
266 270
267 fi 271 fi
268 272
269 } 273 }
270 274
271 antigen-cleanup () { 275 antigen-cleanup () {
272 276
273 # Cleanup unused repositories. 277 # Cleanup unused repositories.
274 278
275 local force=false 279 local force=false
276 if [[ $1 == --force ]]; then 280 if [[ $1 == --force ]]; then
277 force=true 281 force=true
278 fi 282 fi
279 283
280 if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then 284 if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then
281 echo "You don't have any bundles." 285 echo "You don't have any bundles."
282 return 0 286 return 0
283 fi 287 fi
284 288
285 # Find directores in ADOTDIR/repos, that are not in the bundles record. 289 # Find directores in ADOTDIR/repos, that are not in the bundles record.
286 local unused_clones="$(comm -13 \ 290 local unused_clones="$(comm -13 \
287 <(-antigen-echo-record \ 291 <(-antigen-echo-record \
288 | awk '$4 == "true" {print $1}' \ 292 | awk '$4 == "true" {print $1}' \
289 | while read line; do 293 | while read line; do
290 -antigen-get-clone-dir "$line" 294 -antigen-get-clone-dir "$line"
291 done \ 295 done \
292 | sort -u) \ 296 | sort -u) \
293 <(ls -d "$ADOTDIR/repos/"* | sort -u))" 297 <(ls -d "$ADOTDIR/repos/"* | sort -u))"
294 298
295 if [[ -z $unused_clones ]]; then 299 if [[ -z $unused_clones ]]; then
296 echo "You don't have any unidentified bundles." 300 echo "You don't have any unidentified bundles."
297 return 0 301 return 0
298 fi 302 fi
299 303
300 echo 'You have clones for the following repos, but are not used.' 304 echo 'You have clones for the following repos, but are not used.'
301 echo "$unused_clones" \ 305 echo "$unused_clones" \
302 | while read line; do 306 | while read line; do
303 -antigen-get-clone-url "$line" 307 -antigen-get-clone-url "$line"
304 done \ 308 done \
305 | sed -e 's/^/ /' -e 's/|/, branch /' 309 | sed -e 's/^/ /' -e 's/|/, branch /'
306 310
307 if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then 311 if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then
308 echo 312 echo
309 echo 313 echo
310 echo "$unused_clones" | while read line; do 314 echo "$unused_clones" | while read line; do
311 echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." 315 echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..."
312 rm -rf "$line" 316 rm -rf "$line"
313 echo ' done.' 317 echo ' done.'
314 done 318 done
315 else 319 else
316 echo 320 echo
317 echo Nothing deleted. 321 echo Nothing deleted.
318 fi 322 fi
319 } 323 }
320 324
321 antigen-lib () { 325 antigen-lib () {
322 antigen-bundle --loc=lib 326 antigen-bundle --loc=lib
323 } 327 }
324 328
325 antigen-theme () { 329 antigen-theme () {
326 local name="${1:-robbyrussell}" 330 local name="${1:-robbyrussell}"
327 antigen-bundle --loc=themes/$name.zsh-theme --btype=theme 331 antigen-bundle --loc=themes/$name.zsh-theme --btype=theme
328 } 332 }
329 333
330 antigen-apply () { 334 antigen-apply () {
331 # Initialize completion. 335 # Initialize completion.
332 # TODO: Only load completions if there are any changes to the bundle 336 # TODO: Only load completions if there are any changes to the bundle
333 # repositories. 337 # repositories.
334 compinit -i 338 compinit -i
335 } 339 }
336 340
337 antigen-list () { 341 antigen-list () {
338 # List all currently installed bundles. 342 # List all currently installed bundles.
339 if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then 343 if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then
340 echo "You don't have any bundles." >&2 344 echo "You don't have any bundles." >&2
341 return 1 345 return 1
342 else 346 else
343 -antigen-echo-record | sort -u 347 -antigen-echo-record | sort -u
344 fi 348 fi
345 } 349 }
346 350
347 antigen-help () { 351 antigen-help () {
348 cat <<EOF 352 cat <<EOF
349 Antigen is a plugin management system for zsh. It makes it easy to grab awesome 353 Antigen is a plugin management system for zsh. It makes it easy to grab awesome
350 shell scripts and utilities, put up on github. For further details and complete 354 shell scripts and utilities, put up on github. For further details and complete
351 documentation, visit the project's page at 'http://antigen.sharats.me'. 355 documentation, visit the project's page at 'http://antigen.sharats.me'.
352 EOF 356 EOF
353 } 357 }
354 358
355 # A syntax sugar to avoid the `-` when calling antigen commands. With this 359 # A syntax sugar to avoid the `-` when calling antigen commands. With this
356 # function, you can write `antigen-bundle` as `antigen bundle` and so on. 360 # function, you can write `antigen-bundle` as `antigen bundle` and so on.
357 antigen () { 361 antigen () {
358 local cmd="$1" 362 local cmd="$1"
359 shift 363 shift
360 "antigen-$cmd" "$@" 364 "antigen-$cmd" "$@"
361 } 365 }
362 366
363 # Echo the bundle specs as in the record. The first line is not echoed since it 367 # Echo the bundle specs as in the record. The first line is not echoed since it
364 # is a blank line. 368 # is a blank line.
365 -antigen-echo-record () { 369 -antigen-echo-record () {
366 echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' 370 echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p'
367 } 371 }
368 372
369 -antigen-env-setup () { 373 -antigen-env-setup () {
370 # Pre-startup initializations. 374 # Pre-startup initializations.
371 -set-default ANTIGEN_DEFAULT_REPO_URL \ 375 -set-default ANTIGEN_DEFAULT_REPO_URL \
372 https://github.com/robbyrussell/oh-my-zsh.git 376 https://github.com/robbyrussell/oh-my-zsh.git
373 -set-default ADOTDIR $HOME/.antigen 377 -set-default ADOTDIR $HOME/.antigen
374 378
375 # Load the compinit module. 379 # Load the compinit module.
376 autoload -U compinit 380 autoload -U compinit
377 381
378 # Without the following, `compdef` function is not defined. 382 # Without the following, `compdef` function is not defined.
379 compinit -i 383 compinit -i
380 } 384 }
381 385
382 # Same as `export $1=$2`, but will only happen if the name specified by `$1` is 386 # Same as `export $1=$2`, but will only happen if the name specified by `$1` is
383 # not already set. 387 # not already set.
384 -set-default () { 388 -set-default () {
385 local arg_name="$1" 389 local arg_name="$1"
386 local arg_value="$2" 390 local arg_value="$2"
387 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" 391 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'"
388 } 392 }
389 393
390 -antigen-env-setup 394 -antigen-env-setup
391 395
tests/branch-bundle.t
1 Branch b1. 1 Branch b1.
2 2
3 $ pg branch b1 3 $ pg branch b1
4 $ pg checkout b1 4 $ pg checkout b1
5 Switched to branch 'b1' 5 Switched to branch 'b1'
6 $ cat > $PLUGIN_DIR/aliases.zsh <<EOF 6 $ cat > $PLUGIN_DIR/aliases.zsh <<EOF
7 > alias hehe='echo hehe from b1' 7 > alias hehe='echo hehe from b1'
8 > EOF 8 > EOF
9 $ pg commit -am 'Change for b1' 9 $ pg commit -am 'Change for b1'
10 \[b1 [a-f0-9]{7}\] Change for b1 (re) 10 \[b1 [a-f0-9]{7}\] Change for b1 (re)
11 1 file changed, 1 insertion(+), 1 deletion(-) 11 1 file changed, 1 insertion(+), 1 deletion(-)
12 12
13 Go back to master. 13 Go back to master.
14 14
15 $ pg checkout master 15 $ pg checkout master
16 Switched to branch 'master' 16 Switched to branch 'master'
17 17
18 Load plugin from b1. 18 Load plugin from b1.
19 19
20 $ antigen-bundle $PLUGIN_DIR --branch=b1 20 $ antigen-bundle $PLUGIN_DIR --branch=b1
21 Cloning into '.+?'\.\.\. (re) 21 Cloning into '.+?'\.\.\. (re)
22 done. 22 done.
23 Switched to a new branch 'b1' 23 Switched to a new branch 'b1'
24 Branch b1 set up to track remote branch b1 from origin. 24 Branch b1 set up to track remote branch b1 from origin.
25 $ hehe 25 $ hehe
26 hehe from b1 26 hehe from b1
27 27
28 Does not say 'Already on b1' on each session startup.
29
30 $ antigen-bundle $PLUGIN_DIR --branch=b1
31
28 Load plugin from master. 32 Load plugin from master.
29 33
30 $ antigen-bundle $PLUGIN_DIR 34 $ antigen-bundle $PLUGIN_DIR
31 Cloning into '.+?'\.\.\. (re) 35 Cloning into '.+?'\.\.\. (re)
32 done. 36 done.
33 $ hehe 37 $ hehe
34 hehe 38 hehe
35 39