Commit c17d243a69c4cc0f1d8f52837982c342eba9e5e6

Authored by Shrikant Sharat
1 parent 280ec44811

Removed unused load argumet to bundle command.

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