Commit 5d199ab209c17b06f275dae5ba2e7e667778d1f3

Authored by Shrikant Sharat
1 parent 1cae4fc91f

Print the repo url being pulled in, on -update. #10.

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