Commit d535ba468a72b9ad19747d09e755fe857c1856bd

Authored by Shrikant Sharat
1 parent 24fbcce0a0

Introduced a new btype argument to bundle command.

The `name` argument will be phased out. Instead, the btype will indicate the
type of a plugin. Currently it can have valuse of plugin and theme.

Showing 1 changed file with 34 additions and 27 deletions Side-by-side Diff

... ... @@ -2,7 +2,8 @@
2 2  
3 3 # Each line in this string has the following entries separated by a space
4 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 +# <bundle-type>
6 7 # FIXME: Is not kept local by zsh!
7 8 local _ANTIGEN_BUNDLE_RECORD=""
8 9  
... ... @@ -14,6 +15,7 @@ bundle () {
14 15 local url="$ANTIGEN_DEFAULT_REPO_URL"
15 16 local loc=/
16 17 local name=
  18 + local btype=plugin
17 19 local load=true
18 20  
19 21 # Set spec values based on the positional arguments.
... ... @@ -60,11 +62,12 @@ bundle () {
60 62 fi
61 63  
62 64 # Add it to the record.
63   - _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$name $url $loc $clone_dir"
  65 + _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$name $url $loc $clone_dir $btype"
64 66  
65 67 # Load it, unless specified otherwise.
66 68 if $load; then
67   - bundle-load "$name"
  69 + # bundle-load "$name"
  70 + bundle-load "$clone_dir/$loc" "$btype"
68 71 fi
69 72 }
70 73  
... ... @@ -100,6 +103,7 @@ bundle-install () {
100 103 local url="$(echo "$spec" | awk '{print $2}')"
101 104 local loc="$(echo "$spec" | awk '{print $3}')"
102 105 local clone_dir="$(echo "$spec" | awk '{print $4}')"
  106 + local btype="$(echo "$spec" | awk '{print $5}')"
103 107  
104 108 if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then
105 109 if [[ ! -d $clone_dir ]]; then
... ... @@ -121,7 +125,7 @@ bundle-install () {
121 125 cp "$clone_dir/$loc" "$ADOTDIR/bundles/$name"
122 126 fi
123 127  
124   - bundle-load "$name"
  128 + bundle-load "$clone_dir/$loc" "$btype"
125 129  
126 130 done
127 131  
... ... @@ -172,42 +176,45 @@ bundle-cleanup () {
172 176  
173 177 bundle-load () {
174 178  
175   - local name="$1"
176   - local bundle_dir="$ADOTDIR/bundles/$name"
  179 + local location="$1"
  180 + local btype="$2"
177 181  
178   - # Source the plugin script
179   - local script_loc="$bundle_dir/$name.plugin.zsh"
180   - if [[ -f $script_loc ]]; then
181   - source "$script_loc"
182   - fi
  182 + if [[ $btype == theme ]]; then
183 183  
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.
186   - if [[ $name == *.lib ]]; then
187   - # FIXME: This throws an error if no files match the given glob pattern.
188   - for lib ($bundle_dir/*.zsh) source $lib
189   - fi
  184 + # Of course, if its a theme, the location would point to the script
  185 + # file.
  186 + source "$location"
190 187  
191   - # If the name ends with `.theme`, it is handled as if it were a zsh-theme
192   - # plugin.
193   - if [[ $name == *.theme ]]; then
194   - local theme_file="$bundle_dir/${name%.theme}.zsh-theme"
195   - test -f "$theme_file" && source "$theme_file"
196   - fi
  188 + else
197 189  
198   - # Add to $fpath, for completion(s)
199   - fpath=($bundle_dir $fpath)
  190 + # Source the plugin script
  191 + # FIXME: I don't know. Looks very very ugly. Needs a better
  192 + # implementation once tests are ready.
  193 + local script_loc="$(ls "$location" | grep -m1 '.plugin.zsh$')"
  194 + if [[ -f $script_loc ]]; then
  195 + # If we have a `*.plugin.zsh`, source it.
  196 + source "$script_loc"
  197 + elif [[ ! -z "$(ls "$location" | grep -m1 '.zsh$')" ]]; then
  198 + # If there is no `*.plugin.zsh` file, source *all* the `*.zsh`
  199 + # files.
  200 + for script ($location/*.zsh) source "$script"
  201 + fi
  202 +
  203 + # Add to $fpath, for completion(s)
  204 + fpath=($location $fpath)
  205 +
  206 + fi
200 207  
201 208 }
202 209  
203 210 bundle-lib () {
204   - bundle --name=oh-my-zsh.lib --loc=lib
  211 + bundle --loc=lib
205 212 }
206 213  
207 214 bundle-theme () {
208 215 local url="$ANTIGEN_DEFAULT_REPO_URL"
209 216 local name="${1:-robbyrussell}"
210   - bundle-install "$url" --name=$name.theme --loc=themes/$name.zsh-theme
  217 + bundle --loc=themes/$name.zsh-theme --btype=theme
211 218 }
212 219  
213 220 bundle-apply () {