Commit 2b5d4a0c3fe914e713fd51277b4b2a6cad558e21
1 parent
7e0aca7cec
Create symlinks to plugin locations.
Instead of making a copy and fixing problems with it (like copying/excluding .git), we now simply create a soft link to the plugin location.
Showing 1 changed file with 3 additions and 5 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 | # Check if url is just the plugin name. Super short syntax. | 30 | # Check if url is just the plugin name. Super short syntax. |
| 31 | if [[ "$url" != */* ]]; then | 31 | if [[ "$url" != */* ]]; then |
| 32 | loc="plugins/$url" | 32 | loc="plugins/$url" |
| 33 | url="$ANTIGEN_DEFAULT_REPO_URL" | 33 | url="$ANTIGEN_DEFAULT_REPO_URL" |
| 34 | fi | 34 | fi |
| 35 | 35 | ||
| 36 | # Set spec values from keyword arguments, if any. The remaining arguments | 36 | # Set spec values from keyword arguments, if any. The remaining arguments |
| 37 | # are all assumed to be keyword arguments. | 37 | # are all assumed to be keyword arguments. |
| 38 | while [[ $1 == --*=* ]]; do | 38 | while [[ $1 == --*=* ]]; do |
| 39 | arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" | 39 | arg_name="$(echo "$1" | cut -d= -f1 | sed 's/^--//')" |
| 40 | arg_value="$(echo "$1" | cut -d= -f2)" | 40 | arg_value="$(echo "$1" | cut -d= -f2)" |
| 41 | eval "local $arg_name='$arg_value'" | 41 | eval "local $arg_name='$arg_value'" |
| 42 | shift | 42 | shift |
| 43 | done | 43 | done |
| 44 | 44 | ||
| 45 | # Resolve the url. | 45 | # Resolve the url. |
| 46 | if [[ $url != git://* && $url != https://* ]]; then | 46 | if [[ $url != git://* && $url != https://* ]]; then |
| 47 | url="${url%.git}" | 47 | url="${url%.git}" |
| 48 | name="$(basename "$url")" | 48 | name="$(basename "$url")" |
| 49 | url="https://github.com/$url.git" | 49 | url="https://github.com/$url.git" |
| 50 | fi | 50 | fi |
| 51 | 51 | ||
| 52 | # Plugin's repo will be cloned here. | 52 | # Plugin's repo will be cloned here. |
| 53 | local clone_dir="$ANTIGEN_REPO_CACHE/$(echo "$url" \ | 53 | local clone_dir="$ANTIGEN_REPO_CACHE/$(echo "$url" \ |
| 54 | | sed -e 's/\.git$//' -e 's./.-SLASH-.g' -e 's.:.-COLON-.g')" | 54 | | sed -e 's/\.git$//' -e 's./.-SLASH-.g' -e 's.:.-COLON-.g')" |
| 55 | 55 | ||
| 56 | # Make an intelligent guess about the name of the plugin, if not already | 56 | # Make an intelligent guess about the name of the plugin, if not already |
| 57 | # done or is explicitly specified. | 57 | # done or is explicitly specified. |
| 58 | if [[ -z $name ]]; then | 58 | if [[ -z $name ]]; then |
| 59 | name="$(basename $url/$loc)" | 59 | name="$(basename $url/$loc)" |
| 60 | fi | 60 | fi |
| 61 | 61 | ||
| 62 | # Add it to the record. | 62 | # Add it to the record. |
| 63 | bundles="$bundles\n$name $url $loc $clone_dir" | 63 | bundles="$bundles\n$name $url $loc $clone_dir" |
| 64 | 64 | ||
| 65 | # Load it, unless specified otherwise. | 65 | # Load it, unless specified otherwise. |
| 66 | if $load; then | 66 | if $load; then |
| 67 | bundle-load "$name" | 67 | bundle-load "$name" |
| 68 | fi | 68 | fi |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | bundle-install () { | 71 | bundle-install () { |
| 72 | 72 | ||
| 73 | if [[ $1 == --update ]]; then | 73 | if [[ $1 == --update ]]; then |
| 74 | local update=true | 74 | local update=true |
| 75 | else | 75 | else |
| 76 | local update=false | 76 | local update=false |
| 77 | fi | 77 | fi |
| 78 | 78 | ||
| 79 | mkdir -p "$ANTIGEN_BUNDLE_DIR" | 79 | mkdir -p "$ANTIGEN_BUNDLE_DIR" |
| 80 | 80 | ||
| 81 | local handled_repos="" | 81 | local handled_repos="" |
| 82 | 82 | ||
| 83 | echo-non-empty "$bundles" | while read spec; do | 83 | echo-non-empty "$bundles" | while read spec; do |
| 84 | echo "-> $spec" | 84 | echo "-> $spec" |
| 85 | 85 | ||
| 86 | local name="$(echo "$spec" | awk '{print $1}')" | 86 | local name="$(echo "$spec" | awk '{print $1}')" |
| 87 | local url="$(echo "$spec" | awk '{print $2}')" | 87 | local url="$(echo "$spec" | awk '{print $2}')" |
| 88 | local loc="$(echo "$spec" | awk '{print $3}')" | 88 | local loc="$(echo "$spec" | awk '{print $3}')" |
| 89 | local clone_dir="$(echo "$spec" | awk '{print $4}')" | 89 | local clone_dir="$(echo "$spec" | awk '{print $4}')" |
| 90 | 90 | ||
| 91 | if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then | 91 | if [[ -z "$(echo "$handled_repos" | grep -Fm1 "$url")" ]]; then |
| 92 | if [[ ! -d $clone_dir ]]; then | 92 | if [[ ! -d $clone_dir ]]; then |
| 93 | git clone "$url" "$clone_dir" | 93 | git clone "$url" "$clone_dir" |
| 94 | elif $update; then | 94 | elif $update; then |
| 95 | git --git-dir "$clone_dir/.git" pull | 95 | git --git-dir "$clone_dir/.git" pull |
| 96 | fi | 96 | fi |
| 97 | 97 | ||
| 98 | handled_repos="$handled_repos\n$url" | 98 | handled_repos="$handled_repos\n$url" |
| 99 | fi | 99 | fi |
| 100 | 100 | ||
| 101 | if [[ $name != *.theme ]]; then | 101 | if [[ $name != *.theme ]]; then |
| 102 | echo Installing $name | 102 | echo Installing $name |
| 103 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" | 103 | local bundle_dest="$ANTIGEN_BUNDLE_DIR/$name" |
| 104 | pushd "$clone_dir/$loc" > /dev/null | 104 | test -e "$bundle_dest" && rm -rf "$bundle_dest" |
| 105 | ls | grep -Fv '.git' \ | 105 | ln -sT "$clone_dir/$loc" "$bundle_dest" |
| 106 | | xargs cp -rt "$ANTIGEN_BUNDLE_DIR/$name" | ||
| 107 | popd > /dev/null | ||
| 108 | else | 106 | else |
| 109 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" | 107 | mkdir -p "$ANTIGEN_BUNDLE_DIR/$name" |
| 110 | cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" | 108 | cp "$clone_dir/$loc" "$ANTIGEN_BUNDLE_DIR/$name" |
| 111 | fi | 109 | fi |
| 112 | 110 | ||
| 113 | bundle-load "$name" | 111 | bundle-load "$name" |
| 114 | 112 | ||
| 115 | done | 113 | done |
| 116 | 114 | ||
| 117 | } | 115 | } |
| 118 | 116 | ||
| 119 | bundle-install! () { | 117 | bundle-install! () { |
| 120 | bundle-install --update | 118 | bundle-install --update |
| 121 | } | 119 | } |
| 122 | 120 | ||
| 123 | bundle-cleanup () { | 121 | bundle-cleanup () { |
| 124 | 122 | ||
| 125 | # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. | 123 | # Find directores in ANTIGEN_BUNDLE_DIR, that are not in the bundles record. |
| 126 | local unidentified_bundles="$(comm -13 \ | 124 | local unidentified_bundles="$(comm -13 \ |
| 127 | <(echo-non-empty "$bundles" | awk '{print $1}' | sort) \ | 125 | <(echo-non-empty "$bundles" | awk '{print $1}' | sort) \ |
| 128 | <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" | 126 | <(ls -1 "$ANTIGEN_BUNDLE_DIR"))" |
| 129 | 127 | ||
| 130 | if [[ -z $unidentified_bundles ]]; then | 128 | if [[ -z $unidentified_bundles ]]; then |
| 131 | echo "You don't have any unidentified bundles." | 129 | echo "You don't have any unidentified bundles." |
| 132 | return 0 | 130 | return 0 |
| 133 | fi | 131 | fi |
| 134 | 132 | ||
| 135 | echo The following bundles are not recorded: | 133 | echo The following bundles are not recorded: |
| 136 | echo "$unidentified_bundles" | sed 's/^/ /' | 134 | echo "$unidentified_bundles" | sed 's/^/ /' |
| 137 | 135 | ||
| 138 | echo -n '\nDelete them all? [y/N] ' | 136 | echo -n '\nDelete them all? [y/N] ' |
| 139 | if read -q; then | 137 | if read -q; then |
| 140 | echo | 138 | echo |
| 141 | echo | 139 | echo |
| 142 | echo "$unidentified_bundles" | while read name; do | 140 | echo "$unidentified_bundles" | while read name; do |
| 143 | echo -n Deleting $name... | 141 | echo -n Deleting $name... |
| 144 | rm -rf "$ANTIGEN_BUNDLE_DIR/$name" | 142 | rm -rf "$ANTIGEN_BUNDLE_DIR/$name" |
| 145 | echo ' done.' | 143 | echo ' done.' |
| 146 | done | 144 | done |
| 147 | else | 145 | else |
| 148 | echo | 146 | echo |
| 149 | echo Nothing deleted. | 147 | echo Nothing deleted. |
| 150 | fi | 148 | fi |
| 151 | } | 149 | } |
| 152 | 150 | ||
| 153 | bundle-load () { | 151 | bundle-load () { |
| 154 | if [[ $1 == --init ]]; then | 152 | if [[ $1 == --init ]]; then |
| 155 | do_init=true | 153 | do_init=true |
| 156 | shift | 154 | shift |
| 157 | else | 155 | else |
| 158 | do_init=false | 156 | do_init=false |
| 159 | fi | 157 | fi |
| 160 | 158 | ||
| 161 | name="$1" | 159 | name="$1" |
| 162 | bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" | 160 | bundle_dir="$ANTIGEN_BUNDLE_DIR/$name" |
| 163 | 161 | ||
| 164 | # Source the plugin script | 162 | # Source the plugin script |
| 165 | script_loc="$bundle_dir/$name.plugin.zsh" | 163 | script_loc="$bundle_dir/$name.plugin.zsh" |
| 166 | if [[ -f $script_loc ]]; then | 164 | if [[ -f $script_loc ]]; then |
| 167 | source "$script_loc" | 165 | source "$script_loc" |
| 168 | fi | 166 | fi |
| 169 | 167 | ||
| 170 | # If the name of the plugin ends with `.lib`, all the *.zsh files in it are | 168 | # If the name of the plugin ends with `.lib`, all the *.zsh files in it are |
| 171 | # sourced. This is kind of a hack to source the libraries of oh-my-zsh. | 169 | # sourced. This is kind of a hack to source the libraries of oh-my-zsh. |
| 172 | if [[ $name == *.lib ]]; then | 170 | if [[ $name == *.lib ]]; then |
| 173 | # FIXME: This throws an error if no files match the given glob pattern. | 171 | # FIXME: This throws an error if no files match the given glob pattern. |
| 174 | for lib ($bundle_dir/*.zsh) source $lib | 172 | for lib ($bundle_dir/*.zsh) source $lib |
| 175 | fi | 173 | fi |
| 176 | 174 | ||
| 177 | # If the name ends with `.theme`, it is handled as if it were a zsh-theme | 175 | # If the name ends with `.theme`, it is handled as if it were a zsh-theme |
| 178 | # plugin. | 176 | # plugin. |
| 179 | if [[ $name == *.theme ]]; then | 177 | if [[ $name == *.theme ]]; then |
| 180 | source "$bundle_dir/${name%.theme}.zsh-theme" | 178 | source "$bundle_dir/${name%.theme}.zsh-theme" |
| 181 | fi | 179 | fi |
| 182 | 180 | ||
| 183 | # Add to $fpath, if it provides completion | 181 | # Add to $fpath, if it provides completion |
| 184 | if [[ -f "$bundle_dir/_$name" ]]; then | 182 | if [[ -f "$bundle_dir/_$name" ]]; then |
| 185 | fpath=($bundle_dir $fpath) | 183 | fpath=($bundle_dir $fpath) |
| 186 | fi | 184 | fi |
| 187 | 185 | ||
| 188 | if $do_init; then | 186 | if $do_init; then |
| 189 | bundle-init | 187 | bundle-init |
| 190 | fi | 188 | fi |
| 191 | } | 189 | } |
| 192 | 190 | ||
| 193 | bundle-lib () { | 191 | bundle-lib () { |
| 194 | bundle --name=oh-my-zsh.lib --loc=lib | 192 | bundle --name=oh-my-zsh.lib --loc=lib |
| 195 | } | 193 | } |
| 196 | 194 | ||
| 197 | bundle-theme () { | 195 | bundle-theme () { |
| 198 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 196 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
| 199 | local name="${1:-robbyrussell}" | 197 | local name="${1:-robbyrussell}" |
| 200 | bundle "$url" --name=$name.theme --loc=themes/$name.zsh-theme | 198 | bundle "$url" --name=$name.theme --loc=themes/$name.zsh-theme |
| 201 | } | 199 | } |
| 202 | 200 | ||
| 203 | bundle-init () { | 201 | bundle-init () { |
| 204 | # Initialize completion. | 202 | # Initialize completion. |
| 205 | # FIXME: Ensure this runs only once. | 203 | # FIXME: Ensure this runs only once. |
| 206 | autoload -U compinit | 204 | autoload -U compinit |
| 207 | compinit -i | 205 | compinit -i |
| 208 | } | 206 | } |
| 209 | 207 | ||
| 210 | # Does what it says. | 208 | # Does what it says. |
| 211 | echo-non-empty () { | 209 | echo-non-empty () { |
| 212 | echo "$@" | while read line; do | 210 | echo "$@" | while read line; do |
| 213 | [[ $line != "" ]] && echo $line | 211 | [[ $line != "" ]] && echo $line |
| 214 | done | 212 | done |
| 215 | } | 213 | } |
| 216 | 214 | ||
| 217 | -bundle-env-setup () { | 215 | -bundle-env-setup () { |
| 218 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 216 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
| 219 | https://github.com/robbyrussell/oh-my-zsh.git | 217 | https://github.com/robbyrussell/oh-my-zsh.git |
| 220 | -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache | 218 | -set-default ANTIGEN_REPO_CACHE $HOME/.antigen/cache |
| 221 | -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles | 219 | -set-default ANTIGEN_BUNDLE_DIR $HOME/.antigen/bundles |
| 222 | } | 220 | } |
| 223 | 221 | ||
| 224 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is | 222 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is |
| 225 | # not already set. | 223 | # not already set. |
| 226 | -set-default () { | 224 | -set-default () { |
| 227 | arg_name="$1" | 225 | arg_name="$1" |
| 228 | arg_value="$2" | 226 | arg_value="$2" |
| 229 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 227 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
| 230 | } | 228 | } |
| 231 | 229 | ||
| 232 | -bundle-env-setup | 230 | -bundle-env-setup |
| 233 | bundle-init | 231 | bundle-init |
| 234 | 232 |