Commit 1ba08957c44fdfad0581e2705e4e9494833a11f4
1 parent
36cb718564
Fix repo plugins not being copied.
Trying to copy the .git directory is futile in some situations. So, copy everything else except of .git directories.
Showing 1 changed file with 7 additions and 1 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 | # <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 | name="$(basename "$url")" | 41 | name="$(basename "$url")" |
42 | url="https://github.com/${url%.git}.git" | 42 | url="https://github.com/${url%.git}.git" |
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 | echo "-> $spec" | ||
77 | 78 | ||
78 | local name="$(echo "$spec" | awk '{print $1}')" | 79 | local name="$(echo "$spec" | awk '{print $1}')" |
79 | local url="$(echo "$spec" | awk '{print $2}')" | 80 | local url="$(echo "$spec" | awk '{print $2}')" |
80 | local loc="$(echo "$spec" | awk '{print $3}')" | 81 | local loc="$(echo "$spec" | awk '{print $3}')" |
81 | local clone_dir="$(echo "$spec" | awk '{print $4}')" | 82 | local clone_dir="$(echo "$spec" | awk '{print $4}')" |
82 | 83 | ||
83 | if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then | 84 | if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then |
84 | if [[ ! -d $clone_dir ]]; then | 85 | if [[ ! -d $clone_dir ]]; then |
85 | git clone "$url" "$clone_dir" | 86 | git clone "$url" "$clone_dir" |
86 | elif $update; then | 87 | elif $update; then |
87 | git --git-dir "$clone_dir/.git" pull | 88 | git --git-dir "$clone_dir/.git" pull |
88 | fi | 89 | fi |
89 | 90 | ||
90 | handled_repos="$handled_repos\n$url" | 91 | handled_repos="$handled_repos\n$url" |
91 | fi | 92 | fi |
92 | 93 | ||
93 | if [[ $name != *.theme ]]; then | 94 | if [[ $name != *.theme ]]; then |
94 | cp -r "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" | 95 | echo Installing $name |
96 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" | ||
97 | pushd "$clone_dir/$loc" > /dev/null | ||
98 | ls | grep -Fv '.git' \ | ||
99 | | xargs cp -rt "$ANTIGEN_BUNDLE_DIR/$name" | ||
100 | popd > /dev/null | ||
95 | else | 101 | else |
96 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" | 102 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" |
97 | cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" | 103 | cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" |
98 | fi | 104 | fi |
99 | 105 | ||
100 | bundle-load "$name" | 106 | bundle-load "$name" |
101 | 107 | ||
102 | done | 108 | done |
103 | 109 | ||
104 | } | 110 | } |
105 | 111 | ||
106 | bundle-install! () { | 112 | bundle-install! () { |
107 | bundle-install --update | 113 | bundle-install --update |
108 | } | 114 | } |
109 | 115 | ||
110 | bundle-cleanup () { | 116 | bundle-cleanup () { |
111 | 117 | ||
112 | # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. | 118 | # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. |
113 | local unidentified_bundles="$(comm -13 \ | 119 | local unidentified_bundles="$(comm -13 \ |
114 | <(echo-non-empty "$bundles" | awk '{print $1}' | sort) \ | 120 | <(echo-non-empty "$bundles" | awk '{print $1}' | sort) \ |
115 | <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" | 121 | <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" |
116 | 122 | ||
117 | if [[ -z $unidentified_bundles ]]; then | 123 | if [[ -z $unidentified_bundles ]]; then |
118 | echo "You don't have any unidentified bundles." | 124 | echo "You don't have any unidentified bundles." |
119 | return 0 | 125 | return 0 |
120 | fi | 126 | fi |
121 | 127 | ||
122 | echo The following bundles are not recorded: | 128 | echo The following bundles are not recorded: |
123 | echo "$unidentified_bundles" | sed 's/^/ /' | 129 | echo "$unidentified_bundles" | sed 's/^/ /' |
124 | 130 | ||
125 | echo -n '\nDelete them all? [y/N] ' | 131 | echo -n '\nDelete them all? [y/N] ' |
126 | if read -q; then | 132 | if read -q; then |
127 | echo | 133 | echo |
128 | echo | 134 | echo |
129 | echo "$unidentified_bundles" | while read name; do | 135 | echo "$unidentified_bundles" | while read name; do |
130 | echo -n Deleting $name... | 136 | echo -n Deleting $name... |
131 | rm -rf "$ANTIGEN_BUNDLE_DIR/$name" | 137 | rm -rf "$ANTIGEN_BUNDLE_DIR/$name" |
132 | echo ' done.' | 138 | echo ' done.' |
133 | done | 139 | done |
134 | else | 140 | else |
135 | echo | 141 | echo |
136 | echo Nothing deleted. | 142 | echo Nothing deleted. |
137 | fi | 143 | fi |
138 | } | 144 | } |
139 | 145 | ||
140 | bundle-load () { | 146 | bundle-load () { |
141 | if [[ $1 == --init ]]; then | 147 | if [[ $1 == --init ]]; then |
142 | do_init=true | 148 | do_init=true |
143 | shift | 149 | shift |
144 | else | 150 | else |
145 | do_init=false | 151 | do_init=false |
146 | fi | 152 | fi |
147 | 153 | ||
148 | name="$1" | 154 | name="$1" |
149 | bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" | 155 | bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" |
150 | 156 | ||
151 | # Source the plugin script | 157 | # Source the plugin script |
152 | script_loc="$bundle_dir/$name.plugin.zsh" | 158 | script_loc="$bundle_dir/$name.plugin.zsh" |
153 | if [[ -f $script_loc ]]; then | 159 | if [[ -f $script_loc ]]; then |
154 | source "$script_loc" | 160 | source "$script_loc" |
155 | fi | 161 | fi |
156 | 162 | ||
157 | # If the name of the plugin ends with `.lib`, all the *.zsh files in it are | 163 | # If the name of the plugin ends with `.lib`, all the *.zsh files in it are |
158 | # sourced. This is kind of a hack to source the libraries of oh-my-zsh. | 164 | # sourced. This is kind of a hack to source the libraries of oh-my-zsh. |
159 | if [[ $name == *.lib ]]; then | 165 | if [[ $name == *.lib ]]; then |
160 | # FIXME: This throws an error if no files match the given glob pattern. | 166 | # FIXME: This throws an error if no files match the given glob pattern. |
161 | for lib ($bundle_dir/*.zsh) source $lib | 167 | for lib ($bundle_dir/*.zsh) source $lib |
162 | fi | 168 | fi |
163 | 169 | ||
164 | # If the name ends with `.theme`, it is handled as if it were a zsh-theme | 170 | # If the name ends with `.theme`, it is handled as if it were a zsh-theme |
165 | # plugin. | 171 | # plugin. |
166 | if [[ $name == *.theme ]]; then | 172 | if [[ $name == *.theme ]]; then |
167 | source "$bundle_dir/${name%.theme}.zsh-theme" | 173 | source "$bundle_dir/${name%.theme}.zsh-theme" |
168 | fi | 174 | fi |
169 | 175 | ||
170 | # Add to $fpath, if it provides completion | 176 | # Add to $fpath, if it provides completion |
171 | if [[ -f "$bundle_dir/_$name" ]]; then | 177 | if [[ -f "$bundle_dir/_$name" ]]; then |
172 | fpath=($bundle_dir $fpath) | 178 | fpath=($bundle_dir $fpath) |
173 | fi | 179 | fi |
174 | 180 | ||
175 | if $do_init; then | 181 | if $do_init; then |
176 | bundle-init | 182 | bundle-init |
177 | fi | 183 | fi |
178 | } | 184 | } |
179 | 185 | ||
180 | bundle-lib () { | 186 | bundle-lib () { |
181 | bundle --name=oh-my-zsh.lib --loc=lib | 187 | bundle --name=oh-my-zsh.lib --loc=lib |
182 | } | 188 | } |
183 | 189 | ||
184 | bundle-theme () { | 190 | bundle-theme () { |
185 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 191 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
186 | local name="${1:-robbyrussell}" | 192 | local name="${1:-robbyrussell}" |
187 | bundle "$url" --name=$name.theme --loc=themes/$name.zsh-theme | 193 | bundle "$url" --name=$name.theme --loc=themes/$name.zsh-theme |
188 | } | 194 | } |
189 | 195 | ||
190 | bundle-init () { | 196 | bundle-init () { |
191 | # Initialize completion. | 197 | # Initialize completion. |
192 | # FIXME: Ensure this runs only once. | 198 | # FIXME: Ensure this runs only once. |
193 | autoload -U compinit | 199 | autoload -U compinit |
194 | compinit -i | 200 | compinit -i |
195 | } | 201 | } |
196 | 202 | ||
197 | # Does what it says. | 203 | # Does what it says. |
198 | echo-non-empty () { | 204 | echo-non-empty () { |
199 | echo "$@" | while read line; do | 205 | echo "$@" | while read line; do |
200 | [[ $line != "" ]] && echo $line | 206 | [[ $line != "" ]] && echo $line |
201 | done | 207 | done |
202 | } | 208 | } |
203 | 209 | ||
204 | -bundle-env-setup () { | 210 | -bundle-env-setup () { |
205 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 211 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
206 | https://github.com/robbyrussell/oh-my-zsh.git | 212 | https://github.com/robbyrussell/oh-my-zsh.git |
207 | -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache | 213 | -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache |
208 | -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles | 214 | -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles |
209 | } | 215 | } |
210 | 216 | ||
211 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is | 217 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is |
212 | # not already set. | 218 | # not already set. |
213 | -set-default () { | 219 | -set-default () { |
214 | arg_name="$1" | 220 | arg_name="$1" |
215 | arg_value="$2" | 221 | arg_value="$2" |
216 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 222 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
217 | } | 223 | } |
218 | 224 | ||
219 | -bundle-env-setup | 225 | -bundle-env-setup |
220 | bundle-init | 226 | bundle-init |
221 | 227 |