Commit 575a537db98e50b027cb4bd6962e4b883887dfda
1 parent
a12d3140ac
Add a bundle-update command to update bundles.
This command replaces the old `bundle-install --update` functionality.
Showing 1 changed file with 7 additions and 0 deletions Inline Diff
antigen.zsh
1 | #!/bin/zsh | 1 | #!/bin/zsh |
2 | 2 | ||
3 | # Each line in this string has the following entries separated by a space | 3 | # Each line in this string has the following entries separated by a space |
4 | # character. | 4 | # character. |
5 | # <repo-url>, <plugin-location>, <bundle-type> | 5 | # <repo-url>, <plugin-location>, <bundle-type> |
6 | # FIXME: Is not kept local by zsh! | 6 | # FIXME: Is not kept local by zsh! |
7 | local _ANTIGEN_BUNDLE_RECORD="" | 7 | local _ANTIGEN_BUNDLE_RECORD="" |
8 | 8 | ||
9 | # Syntaxes | 9 | # Syntaxes |
10 | # bundle <url> [<loc>=/] | 10 | # bundle <url> [<loc>=/] |
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 btype=plugin | 16 | local btype=plugin |
17 | 17 | ||
18 | # Set spec values based on the positional arguments. | 18 | # Set spec values based on the positional arguments. |
19 | local position_args='url loc' | 19 | local position_args='url loc' |
20 | local i=1 | 20 | local i=1 |
21 | while ! [[ -z $1 || $1 == --*=* ]]; do | 21 | while ! [[ -z $1 || $1 == --*=* ]]; do |
22 | local arg_name="$(echo "$position_args" | cut -d\ -f$i)" | 22 | local arg_name="$(echo "$position_args" | cut -d\ -f$i)" |
23 | local arg_value="$1" | 23 | local arg_value="$1" |
24 | eval "local $arg_name='$arg_value'" | 24 | eval "local $arg_name='$arg_value'" |
25 | shift | 25 | shift |
26 | i=$(($i + 1)) | 26 | i=$(($i + 1)) |
27 | done | 27 | done |
28 | 28 | ||
29 | # Check if url is just the plugin name. Super short syntax. | 29 | # Check if url is just the plugin name. Super short syntax. |
30 | if [[ "$url" != */* ]]; then | 30 | if [[ "$url" != */* ]]; then |
31 | loc="plugins/$url" | 31 | loc="plugins/$url" |
32 | url="$ANTIGEN_DEFAULT_REPO_URL" | 32 | url="$ANTIGEN_DEFAULT_REPO_URL" |
33 | fi | 33 | fi |
34 | 34 | ||
35 | # Set spec values from keyword arguments, if any. The remaining arguments | 35 | # Set spec values from keyword arguments, if any. The remaining arguments |
36 | # are all assumed to be keyword arguments. | 36 | # are all assumed to be keyword arguments. |
37 | while [[ $1 == --*=* ]]; do | 37 | while [[ $1 == --*=* ]]; do |
38 | local arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" | 38 | local arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" |
39 | local arg_value="$(echo "$1" | cut -d= -f2)" | 39 | local arg_value="$(echo "$1" | cut -d= -f2)" |
40 | eval "local $arg_name='$arg_value'" | 40 | eval "local $arg_name='$arg_value'" |
41 | shift | 41 | shift |
42 | done | 42 | done |
43 | 43 | ||
44 | # Resolve the url. | 44 | # Resolve the url. |
45 | if [[ $url != git://* && $url != https://* ]]; then | 45 | if [[ $url != git://* && $url != https://* ]]; then |
46 | url="${url%.git}" | 46 | url="${url%.git}" |
47 | url="https://github.com/$url.git" | 47 | url="https://github.com/$url.git" |
48 | fi | 48 | fi |
49 | 49 | ||
50 | # Add it to the record. | 50 | # Add it to the record. |
51 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" | 51 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" |
52 | 52 | ||
53 | -antigen-ensure-repo "$url" | 53 | -antigen-ensure-repo "$url" |
54 | 54 | ||
55 | bundle-load "$url" "$loc" "$btype" | 55 | bundle-load "$url" "$loc" "$btype" |
56 | 56 | ||
57 | } | 57 | } |
58 | 58 | ||
59 | -antigen-get-clone-dir () { | 59 | -antigen-get-clone-dir () { |
60 | # Takes a repo url and gives out the path that this url needs to be cloned | 60 | # Takes a repo url and gives out the path that this url needs to be cloned |
61 | # to. Doesn't actually clone anything. | 61 | # to. Doesn't actually clone anything. |
62 | # TODO: Memoize? | 62 | # TODO: Memoize? |
63 | echo -n $ADOTDIR/repos/ | 63 | echo -n $ADOTDIR/repos/ |
64 | echo "$1" | sed \ | 64 | echo "$1" | sed \ |
65 | -e 's/\.git$//' \ | 65 | -e 's/\.git$//' \ |
66 | -e 's./.-SLASH-.g' \ | 66 | -e 's./.-SLASH-.g' \ |
67 | -e 's.:.-COLON-.g' | 67 | -e 's.:.-COLON-.g' |
68 | } | 68 | } |
69 | 69 | ||
70 | -antigen-ensure-repo () { | 70 | -antigen-ensure-repo () { |
71 | 71 | ||
72 | local update=false | 72 | local update=false |
73 | if [[ $1 == --update ]]; then | 73 | if [[ $1 == --update ]]; then |
74 | update=true | 74 | update=true |
75 | shift | 75 | shift |
76 | fi | 76 | fi |
77 | 77 | ||
78 | local handled_repos="" | 78 | local handled_repos="" |
79 | local install_bundles="" | 79 | local install_bundles="" |
80 | 80 | ||
81 | local url="$1" | 81 | local url="$1" |
82 | local clone_dir="$(-antigen-get-clone-dir $url)" | 82 | local clone_dir="$(-antigen-get-clone-dir $url)" |
83 | 83 | ||
84 | if ! echo "$handled_repos" | grep -Fqm1 "$url"; then | 84 | if ! echo "$handled_repos" | grep -Fqm1 "$url"; then |
85 | if [[ ! -d $clone_dir ]]; then | 85 | if [[ ! -d $clone_dir ]]; then |
86 | git clone "$url" "$clone_dir" | 86 | git clone "$url" "$clone_dir" |
87 | elif $update; then | 87 | elif $update; then |
88 | git --git-dir "$clone_dir/.git" pull | 88 | git --git-dir "$clone_dir/.git" pull |
89 | fi | 89 | fi |
90 | 90 | ||
91 | handled_repos="$handled_repos\n$url" | 91 | handled_repos="$handled_repos\n$url" |
92 | fi | 92 | fi |
93 | 93 | ||
94 | } | 94 | } |
95 | 95 | ||
96 | bundle-update () { | ||
97 | # Update your bundles, i.e., `git pull` in all the plugin repos. | ||
98 | -bundle-echo-record | awk '{print $1}' | sort -u | while read url; do | ||
99 | -antigen-ensure-repo --update "$url" | ||
100 | done | ||
101 | } | ||
102 | |||
96 | bundle-cleanup () { | 103 | bundle-cleanup () { |
97 | 104 | ||
98 | if [[ ! -d "$ADOTDIR/bundles" || \ | 105 | if [[ ! -d "$ADOTDIR/bundles" || \ |
99 | "$(ls "$ADOTDIR/bundles/" | wc -l)" == 0 ]]; then | 106 | "$(ls "$ADOTDIR/bundles/" | wc -l)" == 0 ]]; then |
100 | echo "You don't have any bundles." | 107 | echo "You don't have any bundles." |
101 | return 0 | 108 | return 0 |
102 | fi | 109 | fi |
103 | 110 | ||
104 | # Find directores in ADOTDIR/bundles, that are not in the bundles record. | 111 | # Find directores in ADOTDIR/bundles, that are not in the bundles record. |
105 | local unidentified_bundles="$(comm -13 \ | 112 | local unidentified_bundles="$(comm -13 \ |
106 | <(-bundle-echo-record | awk '{print $1}' | sort) \ | 113 | <(-bundle-echo-record | awk '{print $1}' | sort) \ |
107 | <(ls -1 "$ADOTDIR/bundles"))" | 114 | <(ls -1 "$ADOTDIR/bundles"))" |
108 | 115 | ||
109 | if [[ -z $unidentified_bundles ]]; then | 116 | if [[ -z $unidentified_bundles ]]; then |
110 | echo "You don't have any unidentified bundles." | 117 | echo "You don't have any unidentified bundles." |
111 | return 0 | 118 | return 0 |
112 | fi | 119 | fi |
113 | 120 | ||
114 | echo The following bundles are not recorded: | 121 | echo The following bundles are not recorded: |
115 | echo "$unidentified_bundles" | sed 's/^/ /' | 122 | echo "$unidentified_bundles" | sed 's/^/ /' |
116 | 123 | ||
117 | echo -n '\nDelete them all? [y/N] ' | 124 | echo -n '\nDelete them all? [y/N] ' |
118 | if read -q; then | 125 | if read -q; then |
119 | echo | 126 | echo |
120 | echo | 127 | echo |
121 | echo "$unidentified_bundles" | while read name; do | 128 | echo "$unidentified_bundles" | while read name; do |
122 | echo -n Deleting $name... | 129 | echo -n Deleting $name... |
123 | rm -rf "$ADOTDIR/bundles/$name" | 130 | rm -rf "$ADOTDIR/bundles/$name" |
124 | echo ' done.' | 131 | echo ' done.' |
125 | done | 132 | done |
126 | else | 133 | else |
127 | echo | 134 | echo |
128 | echo Nothing deleted. | 135 | echo Nothing deleted. |
129 | fi | 136 | fi |
130 | } | 137 | } |
131 | 138 | ||
132 | bundle-load () { | 139 | bundle-load () { |
133 | 140 | ||
134 | local url="$1" | 141 | local url="$1" |
135 | local location="$(-antigen-get-clone-dir "$url")/$2" | 142 | local location="$(-antigen-get-clone-dir "$url")/$2" |
136 | local btype="$3" | 143 | local btype="$3" |
137 | 144 | ||
138 | if [[ $btype == theme ]]; then | 145 | if [[ $btype == theme ]]; then |
139 | 146 | ||
140 | # Of course, if its a theme, the location would point to the script | 147 | # Of course, if its a theme, the location would point to the script |
141 | # file. | 148 | # file. |
142 | source "$location" | 149 | source "$location" |
143 | 150 | ||
144 | else | 151 | else |
145 | 152 | ||
146 | # Source the plugin script | 153 | # Source the plugin script |
147 | # FIXME: I don't know. Looks very very ugly. Needs a better | 154 | # FIXME: I don't know. Looks very very ugly. Needs a better |
148 | # implementation once tests are ready. | 155 | # implementation once tests are ready. |
149 | local script_loc="$(ls "$location" | grep -m1 '.plugin.zsh$')" | 156 | local script_loc="$(ls "$location" | grep -m1 '.plugin.zsh$')" |
150 | if [[ -f $script_loc ]]; then | 157 | if [[ -f $script_loc ]]; then |
151 | # If we have a `*.plugin.zsh`, source it. | 158 | # If we have a `*.plugin.zsh`, source it. |
152 | source "$script_loc" | 159 | source "$script_loc" |
153 | elif [[ ! -z "$(ls "$location" | grep -m1 '.zsh$')" ]]; then | 160 | elif [[ ! -z "$(ls "$location" | grep -m1 '.zsh$')" ]]; then |
154 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` | 161 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` |
155 | # files. | 162 | # files. |
156 | for script ($location/*.zsh) source "$script" | 163 | for script ($location/*.zsh) source "$script" |
157 | fi | 164 | fi |
158 | 165 | ||
159 | # Add to $fpath, for completion(s) | 166 | # Add to $fpath, for completion(s) |
160 | fpath=($location $fpath) | 167 | fpath=($location $fpath) |
161 | 168 | ||
162 | fi | 169 | fi |
163 | 170 | ||
164 | } | 171 | } |
165 | 172 | ||
166 | bundle-lib () { | 173 | bundle-lib () { |
167 | bundle --loc=lib | 174 | bundle --loc=lib |
168 | } | 175 | } |
169 | 176 | ||
170 | bundle-theme () { | 177 | bundle-theme () { |
171 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 178 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
172 | local name="${1:-robbyrussell}" | 179 | local name="${1:-robbyrussell}" |
173 | bundle --loc=themes/$name.zsh-theme --btype=theme | 180 | bundle --loc=themes/$name.zsh-theme --btype=theme |
174 | } | 181 | } |
175 | 182 | ||
176 | bundle-apply () { | 183 | bundle-apply () { |
177 | # Initialize completion. | 184 | # Initialize completion. |
178 | # TODO: Doesn't look like this is really necessary. Need to investigate. | 185 | # TODO: Doesn't look like this is really necessary. Need to investigate. |
179 | compinit -i | 186 | compinit -i |
180 | } | 187 | } |
181 | 188 | ||
182 | bundle-list () { | 189 | bundle-list () { |
183 | # List all currently installed bundles | 190 | # List all currently installed bundles |
184 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then | 191 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then |
185 | echo "You don't have any bundles." >&2 | 192 | echo "You don't have any bundles." >&2 |
186 | return 1 | 193 | return 1 |
187 | else | 194 | else |
188 | -bundle-echo-record | awk '{print $1 " " $2 " " $3}' | 195 | -bundle-echo-record | awk '{print $1 " " $2 " " $3}' |
189 | fi | 196 | fi |
190 | } | 197 | } |
191 | 198 | ||
192 | # Echo the bundle specs as in the record. The first line is not echoed since it | 199 | # Echo the bundle specs as in the record. The first line is not echoed since it |
193 | # is a blank line. | 200 | # is a blank line. |
194 | -bundle-echo-record () { | 201 | -bundle-echo-record () { |
195 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' | 202 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' |
196 | } | 203 | } |
197 | 204 | ||
198 | -bundle-env-setup () { | 205 | -bundle-env-setup () { |
199 | # Pre-startup initializations | 206 | # Pre-startup initializations |
200 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 207 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
201 | https://github.com/robbyrussell/oh-my-zsh.git | 208 | https://github.com/robbyrussell/oh-my-zsh.git |
202 | -set-default ADOTDIR $HOME/.antigen | 209 | -set-default ADOTDIR $HOME/.antigen |
203 | 210 | ||
204 | # Load the compinit module | 211 | # Load the compinit module |
205 | autoload -U compinit | 212 | autoload -U compinit |
206 | 213 | ||
207 | # Without the following, `compdef` function is not defined. | 214 | # Without the following, `compdef` function is not defined. |
208 | compinit -i | 215 | compinit -i |
209 | } | 216 | } |
210 | 217 | ||
211 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is | 218 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is |
212 | # not already set. | 219 | # not already set. |
213 | -set-default () { | 220 | -set-default () { |
214 | local arg_name="$1" | 221 | local arg_name="$1" |
215 | local arg_value="$2" | 222 | local arg_value="$2" |
216 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 223 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
217 | } | 224 | } |
218 | 225 | ||
219 | -bundle-env-setup | 226 | -bundle-env-setup |
220 | 227 |