Commit 78b101b2e8f9cbd289cdfeebc53513d012b5fd8f

Authored by Shrikant Sharat
1 parent e5dfac7ea3

bundle-install doesn't automatically update.

bundle-install command now only updates the plugins' repositories, if the
`--update` argument is given to it.

Showing 1 changed file with 3 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 # <bundle-name>, <repo-url>, <plugin-location>, <repo-local-clone-dir> 5 # <bundle-name>, <repo-url>, <plugin-location>, <repo-local-clone-dir>
6 # FIXME: Is not kept local by zsh! 6 # FIXME: Is not kept local by zsh!
7 local bundles="" 7 local bundles=""
8 8
9 # Syntaxes 9 # Syntaxes
10 # bundle <url> [<loc>=/] [<name>] 10 # bundle <url> [<loc>=/] [<name>]
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 name= 16 local name=
17 local load=true 17 local load=true
18 18
19 # Set spec values based on the positional arguments. 19 # Set spec values based on the positional arguments.
20 local position_args='url loc name' 20 local position_args='url loc name'
21 local i=1 21 local i=1
22 while ! [[ -z $1 || $1 == --*=* ]]; do 22 while ! [[ -z $1 || $1 == --*=* ]]; do
23 arg_name="$(echo "$position_args" | cut -d\ -f$i)" 23 arg_name="$(echo "$position_args" | cut -d\ -f$i)"
24 arg_value="$1" 24 arg_value="$1"
25 eval "local $arg_name='$arg_value'" 25 eval "local $arg_name='$arg_value'"
26 shift 26 shift
27 i=$(($i + 1)) 27 i=$(($i + 1))
28 done 28 done
29 29
30 # Set spec values from keyword arguments, if any. The remaining arguments 30 # Set spec values from keyword arguments, if any. The remaining arguments
31 # are all assumed to be keyword arguments. 31 # are all assumed to be keyword arguments.
32 while [[ $1 == --*=* ]]; do 32 while [[ $1 == --*=* ]]; do
33 arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" 33 arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')"
34 arg_value="$(echo "$1" | cut -d= -f2)" 34 arg_value="$(echo "$1" | cut -d= -f2)"
35 eval "local $arg_name='$arg_value'" 35 eval "local $arg_name='$arg_value'"
36 shift 36 shift
37 done 37 done
38 38
39 # Resolve the url. 39 # Resolve the url.
40 if [[ $url != git://* && $url != https://* ]]; then 40 if [[ $url != git://* && $url != https://* ]]; then
41 url="https://github.com/$url.git" 41 url="https://github.com/$url.git"
42 name="$(basename "$url")" 42 name="$(basename "$url")"
43 fi 43 fi
44 44
45 # Plugin's repo will be cloned here. 45 # Plugin's repo will be cloned here.
46 local clone_dir="$ANTIGEN_REPO_CACHE/$(echo "$url" \ 46 local clone_dir="$ANTIGEN_REPO_CACHE/$(echo "$url" \
47 | sed -e 's/\.git$//' -e 's./.-SLASH-.g' -e 's.:.-COLON-.g')" 47 | sed -e 's/\.git$//' -e 's./.-SLASH-.g' -e 's.:.-COLON-.g')"
48 48
49 # Make an intelligent guess about the name of the plugin, if not already 49 # Make an intelligent guess about the name of the plugin, if not already
50 # done or is explicitly specified. 50 # done or is explicitly specified.
51 if [[ -z $name ]]; then 51 if [[ -z $name ]]; then
52 name="$(basename $url/$loc)" 52 name="$(basename $url/$loc)"
53 fi 53 fi
54 54
55 # Add it to the record. 55 # Add it to the record.
56 bundles="$bundles\n$name $url $loc $clone_dir" 56 bundles="$bundles\n$name $url $loc $clone_dir"
57 57
58 # Load it, unless specified otherwise. 58 # Load it, unless specified otherwise.
59 if $load; then 59 if $load; then
60 bundle-load "$name" 60 bundle-load "$name"
61 fi 61 fi
62 } 62 }
63 63
64 bundle-install () { 64 bundle-install () {
65 65
66 if [[ $1 == --update ]]; then 66 if [[ $1 == --update ]]; then
67 local update=true 67 local update=true
68 else 68 else
69 local update=false 69 local update=false
70 fi 70 fi
71 71
72 mkdir -p "$ANTIGEN_BUNDLE_DIR" 72 mkdir -p "$ANTIGEN_BUNDLE_DIR"
73 73
74 local handled_repos="" 74 local handled_repos=""
75 75
76 echo-non-empty "$bundles" | while read spec; do 76 echo-non-empty "$bundles" | while read spec; do
77 77
78 local name="$(echo "$spec" | awk '{print $1}')" 78 local name="$(echo "$spec" | awk '{print $1}')"
79 local url="$(echo "$spec" | awk '{print $2}')" 79 local url="$(echo "$spec" | awk '{print $2}')"
80 local loc="$(echo "$spec" | awk '{print $3}')" 80 local loc="$(echo "$spec" | awk '{print $3}')"
81 local clone_dir="$(echo "$spec" | awk '{print $4}')" 81 local clone_dir="$(echo "$spec" | awk '{print $4}')"
82 82
83 if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then 83 if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then
84 if [[ -d $clone_dir ]]; then 84 if [[ ! -d $clone_dir ]]; then
85 git --git-dir "$clone_dir/.git" pull
86 else
87 git clone "$url" "$clone_dir" 85 git clone "$url" "$clone_dir"
86 elif $update; then
87 git --git-dir "$clone_dir/.git" pull
88 fi 88 fi
89 89
90 handled_repos="$handled_repos\n$url" 90 handled_repos="$handled_repos\n$url"
91 fi 91 fi
92 92
93 if [[ $name != *.theme ]]; then 93 if [[ $name != *.theme ]]; then
94 cp -R "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" 94 cp -R "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name"
95 else 95 else
96 mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" 96 mkdir -p "$ANTIGEN_BUNDLE_DIR/$name"
97 cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" 97 cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name"
98 fi 98 fi
99 99
100 bundle-load "$name" 100 bundle-load "$name"
101 101
102 done 102 done
103 103
104 } 104 }
105 105
106 bundle-load () { 106 bundle-load () {
107 if [[ $1 == --init ]]; then 107 if [[ $1 == --init ]]; then
108 do_init=true 108 do_init=true
109 shift 109 shift
110 else 110 else
111 do_init=false 111 do_init=false
112 fi 112 fi
113 113
114 name="$1" 114 name="$1"
115 bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" 115 bundle_dir="$ANTIGEN_BUNDLE_DIR/$name"
116 116
117 # Source the plugin script 117 # Source the plugin script
118 script_loc="$bundle_dir/$name.plugin.zsh" 118 script_loc="$bundle_dir/$name.plugin.zsh"
119 if [[ -f $script_loc ]]; then 119 if [[ -f $script_loc ]]; then
120 source "$script_loc" 120 source "$script_loc"
121 fi 121 fi
122 122
123 # If the name of the plugin ends with `.lib`, all the *.zsh files in it are 123 # If the name of the plugin ends with `.lib`, all the *.zsh files in it are
124 # sourced. This is kind of a hack to source the libraries of oh-my-zsh. 124 # sourced. This is kind of a hack to source the libraries of oh-my-zsh.
125 if [[ $name == *.lib ]]; then 125 if [[ $name == *.lib ]]; then
126 # FIXME: This throws an error if no files match the given glob pattern. 126 # FIXME: This throws an error if no files match the given glob pattern.
127 for lib ($bundle_dir/*.zsh) source $lib 127 for lib ($bundle_dir/*.zsh) source $lib
128 fi 128 fi
129 129
130 # If the name ends with `.theme`, it is handled as if it were a zsh-theme 130 # If the name ends with `.theme`, it is handled as if it were a zsh-theme
131 # plugin. 131 # plugin.
132 if [[ $name == *.theme ]]; then 132 if [[ $name == *.theme ]]; then
133 source "$bundle_dir/${name%.theme}.zsh-theme" 133 source "$bundle_dir/${name%.theme}.zsh-theme"
134 fi 134 fi
135 135
136 # Add to $fpath, if it provides completion 136 # Add to $fpath, if it provides completion
137 if [[ -f "$bundle_dir/_$name" ]]; then 137 if [[ -f "$bundle_dir/_$name" ]]; then
138 fpath=($bundle_dir $fpath) 138 fpath=($bundle_dir $fpath)
139 fi 139 fi
140 140
141 if $do_init; then 141 if $do_init; then
142 bundle-init 142 bundle-init
143 fi 143 fi
144 } 144 }
145 145
146 bundle-lib () { 146 bundle-lib () {
147 bundle --name=oh-my-zsh.lib --loc=lib 147 bundle --name=oh-my-zsh.lib --loc=lib
148 } 148 }
149 149
150 bundle-theme () { 150 bundle-theme () {
151 local url="$ANTIGEN_DEFAULT_REPO_URL" 151 local url="$ANTIGEN_DEFAULT_REPO_URL"
152 local name="${1:-robbyrussell}" 152 local name="${1:-robbyrussell}"
153 bundle "$url" --name=$name.theme --loc=themes/$name.zsh-theme 153 bundle "$url" --name=$name.theme --loc=themes/$name.zsh-theme
154 } 154 }
155 155
156 bundle-init () { 156 bundle-init () {
157 # Initialize completion. 157 # Initialize completion.
158 # FIXME: Ensure this runs only once. 158 # FIXME: Ensure this runs only once.
159 autoload -U compinit 159 autoload -U compinit
160 compinit -i 160 compinit -i
161 } 161 }
162 162
163 # A python command wrapper. Almost the same as `python -c`, but dedents the 163 # A python command wrapper. Almost the same as `python -c`, but dedents the
164 # source string. 164 # source string.
165 py () { 165 py () {
166 code="$1" 166 code="$1"
167 167
168 # Find indentation from first line. 168 # Find indentation from first line.
169 indent="$(echo "$code" | grep -m1 -v '^$' | grep -o '^\s*' | wc -c)" 169 indent="$(echo "$code" | grep -m1 -v '^$' | grep -o '^\s*' | wc -c)"
170 170
171 # Strip that many spaces in the start from each line. 171 # Strip that many spaces in the start from each line.
172 if [[ $indent != 0 ]]; then 172 if [[ $indent != 0 ]]; then
173 indent=$(($indent - 1)) 173 indent=$(($indent - 1))
174 code="$(echo "$code" | sed "s/^\s\{$indent\}//")" 174 code="$(echo "$code" | sed "s/^\s\{$indent\}//")"
175 fi 175 fi
176 176
177 # Run the piece of code. 177 # Run the piece of code.
178 python -c "$code" 178 python -c "$code"
179 } 179 }
180 180
181 # Does what it says. 181 # Does what it says.
182 echo-non-empty () { 182 echo-non-empty () {
183 echo "$@" | while read line; do 183 echo "$@" | while read line; do
184 [[ $line != "" ]] && echo $line 184 [[ $line != "" ]] && echo $line
185 done 185 done
186 } 186 }
187 187
188 -bundle-env-setup () { 188 -bundle-env-setup () {
189 -set-default ANTIGEN_DEFAULT_REPO_URL \ 189 -set-default ANTIGEN_DEFAULT_REPO_URL \
190 https://github.com/robbyrussell/oh-my-zsh.git 190 https://github.com/robbyrussell/oh-my-zsh.git
191 -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache 191 -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache
192 -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles 192 -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles
193 } 193 }
194 194
195 # Same as `export $1=$2`, but will only happen if the name specified by `$1` is 195 # Same as `export $1=$2`, but will only happen if the name specified by `$1` is
196 # not already set. 196 # not already set.
197 -set-default () { 197 -set-default () {
198 arg_name="$1" 198 arg_name="$1"
199 arg_value="$2" 199 arg_value="$2"
200 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" 200 eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'"
201 } 201 }
202 202
203 -bundle-env-setup 203 -bundle-env-setup