Commit 38b0b0409ee096eb1c12546f64097837e566e3ef
1 parent
d2137eade1
Fix #12. Local bundles can now bypass cloning.
The new `--no-local-clone` argument to -bundle command makes it so that if the bundle specified is a local path, then no new clone is made. The bundle is loaded directly from the given path.
Showing 3 changed files with 19 additions and 10 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 | # <repo-url>, <plugin-location>, <bundle-type> | 5 | # <repo-url>, <plugin-location>, <bundle-type> |
| 6 | # FIXME: Is not kept local by zsh! | 6 | # FIXME: Is not kept local by zsh! |
| 7 | local _ANTIGEN_BUNDLE_RECORD="" | 7 | local _ANTIGEN_BUNDLE_RECORD="" |
| 8 | 8 | ||
| 9 | # Syntaxes | 9 | # Syntaxes |
| 10 | # antigen-bundle <url> [<loc>=/] | 10 | # antigen-bundle <url> [<loc>=/] |
| 11 | # Keyword only arguments: | 11 | # Keyword only arguments: |
| 12 | # branch - The branch of the repo to use for this bundle. | 12 | # branch - The branch of the repo to use for this bundle. |
| 13 | antigen-bundle () { | 13 | antigen-bundle () { |
| 14 | 14 | ||
| 15 | # Bundle spec arguments' default values. | 15 | # Bundle spec arguments' default values. |
| 16 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 16 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
| 17 | local loc=/ | 17 | local loc=/ |
| 18 | local branch= | 18 | local branch= |
| 19 | local no_local_clone=false | ||
| 19 | local btype=plugin | 20 | local btype=plugin |
| 20 | 21 | ||
| 21 | # Set spec values based on the positional arguments. | 22 | # Set spec values based on the positional arguments. |
| 22 | local position_args | 23 | local position_args |
| 23 | position_args=(url loc) | 24 | position_args=(url loc) |
| 24 | local i=1 | 25 | local i=1 |
| 25 | while ! [[ -z $1 || $1 == --*=* ]]; do | 26 | while ! [[ -z $1 || $1 == --*=* ]]; do |
| 26 | local arg_name="${position_args[$i]}" | 27 | local arg_name="${position_args[$i]}" |
| 27 | local arg_value="$1" | 28 | local arg_value="$1" |
| 28 | eval "local $arg_name='$arg_value'" | 29 | eval "local $arg_name='$arg_value'" |
| 29 | shift | 30 | shift |
| 30 | i=$(($i + 1)) | 31 | i=$(($i + 1)) |
| 31 | done | 32 | done |
| 32 | 33 | ||
| 33 | # Set spec values from keyword arguments, if any. The remaining arguments | 34 | # Set spec values from keyword arguments, if any. The remaining arguments |
| 34 | # are all assumed to be keyword arguments. | 35 | # are all assumed to be keyword arguments. |
| 35 | while [[ $1 == --* ]]; do | 36 | while [[ $1 == --* ]]; do |
| 36 | # Remove the `--` at the start and replace the rest of `-`'s to `_`'s. | 37 | # Remove the `--` at the start and replace the rest of `-`'s to `_`'s. |
| 37 | local arg="${${1#--}//-/_}" | 38 | local arg="${${1#--}//-/_}" |
| 38 | 39 | ||
| 39 | if [[ $arg != *=* ]]; then | 40 | if [[ $arg != *=* ]]; then |
| 40 | arg="$arg=true" | 41 | arg="$arg=true" |
| 41 | fi | 42 | fi |
| 42 | 43 | ||
| 43 | local arg_name="${arg%\=*}" | 44 | local arg_name="${arg%\=*}" |
| 44 | local arg_value="${arg#*\=}" | 45 | local arg_value="${arg#*\=}" |
| 45 | 46 | ||
| 46 | eval "local $arg_name='$arg_value'" | 47 | eval "local $arg_name='$arg_value'" |
| 47 | shift | 48 | shift |
| 48 | done | 49 | done |
| 49 | 50 | ||
| 50 | # Check if url is just the plugin name. Super short syntax. | 51 | # Check if url is just the plugin name. Super short syntax. |
| 51 | if [[ "$url" != */* ]]; then | 52 | if [[ "$url" != */* ]]; then |
| 52 | loc="plugins/$url" | 53 | loc="plugins/$url" |
| 53 | url="$ANTIGEN_DEFAULT_REPO_URL" | 54 | url="$ANTIGEN_DEFAULT_REPO_URL" |
| 54 | fi | 55 | fi |
| 55 | 56 | ||
| 56 | # Resolve the url. | 57 | # Resolve the url. |
| 57 | url="$(-antigen-resolve-bundle-url "$url")" | 58 | url="$(-antigen-resolve-bundle-url "$url")" |
| 58 | 59 | ||
| 59 | # Add the branch information to the url. | 60 | # Add the branch information to the url. |
| 60 | if [[ ! -z $branch ]]; then | 61 | if [[ ! -z $branch ]]; then |
| 61 | url="$url|$branch" | 62 | url="$url|$branch" |
| 62 | fi | 63 | fi |
| 63 | 64 | ||
| 64 | # Add it to the record. | 65 | # Add it to the record. |
| 65 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" | 66 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype $no_local_clone" |
| 66 | 67 | ||
| 67 | # Ensure a clone exists for this repo. | 68 | # Ensure a clone exists for this repo, if needed. |
| 68 | -antigen-ensure-repo "$url" | 69 | if ! [[ $url == /* && $no_local_clone == true ]]; then |
| 70 | -antigen-ensure-repo "$url" | ||
| 71 | fi | ||
| 69 | 72 | ||
| 70 | # Load the plugin. | 73 | # Load the plugin. |
| 71 | -antigen-load "$url" "$loc" "$btype" | 74 | -antigen-load "$url" "$loc" "$btype" "$no_local_clone" |
| 72 | 75 | ||
| 73 | } | 76 | } |
| 74 | 77 | ||
| 75 | -antigen-resolve-bundle-url () { | 78 | -antigen-resolve-bundle-url () { |
| 76 | # Given an acceptable short/full form of a bundle's repo url, this function | 79 | # Given an acceptable short/full form of a bundle's repo url, this function |
| 77 | # echoes the full form of the repo's clone url. | 80 | # echoes the full form of the repo's clone url. |
| 78 | 81 | ||
| 79 | local url="$1" | 82 | local url="$1" |
| 80 | 83 | ||
| 81 | # Expand short github url syntax: `username/reponame` | 84 | # Expand short github url syntax: `username/reponame` |
| 82 | if [[ $url != git://* && \ | 85 | if [[ $url != git://* && \ |
| 83 | $url != https://* && \ | 86 | $url != https://* && \ |
| 84 | $url != /* && \ | 87 | $url != /* && \ |
| 85 | $url != git@github.com:*/* | 88 | $url != git@github.com:*/* |
| 86 | ]]; then | 89 | ]]; then |
| 87 | url="https://github.com/${url%.git}.git" | 90 | url="https://github.com/${url%.git}.git" |
| 88 | fi | 91 | fi |
| 89 | 92 | ||
| 90 | echo "$url" | 93 | echo "$url" |
| 91 | } | 94 | } |
| 92 | 95 | ||
| 93 | antigen-bundles () { | 96 | antigen-bundles () { |
| 94 | # Bulk add many bundles at one go. Empty lines and lines starting with a `#` | 97 | # Bulk add many bundles at one go. Empty lines and lines starting with a `#` |
| 95 | # are ignored. Everything else is given to `antigen-bundle` as is, no | 98 | # are ignored. Everything else is given to `antigen-bundle` as is, no |
| 96 | # quoting rules applied. | 99 | # quoting rules applied. |
| 97 | 100 | ||
| 98 | local line | 101 | local line |
| 99 | 102 | ||
| 100 | grep -v '^\s*$\|^#' | while read line; do | 103 | grep -v '^\s*$\|^#' | while read line; do |
| 101 | # Using `eval` so that we can use the shell-style quoting in each line | 104 | # Using `eval` so that we can use the shell-style quoting in each line |
| 102 | # piped to `antigen-bundles`. | 105 | # piped to `antigen-bundles`. |
| 103 | eval "antigen-bundle $line" | 106 | eval "antigen-bundle $line" |
| 104 | done | 107 | done |
| 105 | } | 108 | } |
| 106 | 109 | ||
| 107 | antigen-update () { | 110 | antigen-update () { |
| 108 | # Update your bundles, i.e., `git pull` in all the plugin repos. | 111 | # Update your bundles, i.e., `git pull` in all the plugin repos. |
| 109 | -antigen-echo-record \ | 112 | -antigen-echo-record \ |
| 110 | | awk '{print $1}' \ | 113 | | awk '{print $1}' \ |
| 111 | | sort -u \ | 114 | | sort -u \ |
| 112 | | while read url; do | 115 | | while read url; do |
| 113 | echo "**** Pulling $url" | 116 | echo "**** Pulling $url" |
| 114 | -antigen-ensure-repo --update --verbose "$url" | 117 | -antigen-ensure-repo --update --verbose "$url" |
| 115 | echo | 118 | echo |
| 116 | done | 119 | done |
| 117 | } | 120 | } |
| 118 | 121 | ||
| 119 | -antigen-get-clone-dir () { | 122 | -antigen-get-clone-dir () { |
| 120 | # Takes a repo url and gives out the path that this url needs to be cloned | 123 | # Takes a repo url and gives out the path that this url needs to be cloned |
| 121 | # to. Doesn't actually clone anything. | 124 | # to. Doesn't actually clone anything. |
| 122 | # TODO: Memoize? | 125 | # TODO: Memoize? |
| 123 | 126 | ||
| 124 | # The url given. | 127 | # The url given. |
| 125 | local url="$1" | 128 | local url="$1" |
| 126 | 129 | ||
| 127 | # Echo the full path to the clone directory. | 130 | # Echo the full path to the clone directory. |
| 128 | echo -n $ADOTDIR/repos/ | 131 | echo -n $ADOTDIR/repos/ |
| 129 | echo "$url" | sed \ | 132 | echo "$url" | sed \ |
| 130 | -e 's./.-SLASH-.g' \ | 133 | -e 's./.-SLASH-.g' \ |
| 131 | -e 's.:.-COLON-.g' \ | 134 | -e 's.:.-COLON-.g' \ |
| 132 | -e 's.|.-PIPE-.g' | 135 | -e 's.|.-PIPE-.g' |
| 133 | } | 136 | } |
| 134 | 137 | ||
| 135 | -antigen-get-clone-url () { | 138 | -antigen-get-clone-url () { |
| 136 | # Takes a repo's clone dir and gives out the repo's original url that was | 139 | # Takes a repo's clone dir and gives out the repo's original url that was |
| 137 | # used to create the given directory path. | 140 | # used to create the given directory path. |
| 138 | # TODO: Memoize? | 141 | # TODO: Memoize? |
| 139 | echo "$1" | sed \ | 142 | echo "$1" | sed \ |
| 140 | -e "s:^$ADOTDIR/repos/::" \ | 143 | -e "s:^$ADOTDIR/repos/::" \ |
| 141 | -e 's.-SLASH-./.g' \ | 144 | -e 's.-SLASH-./.g' \ |
| 142 | -e 's.-COLON-.:.g' \ | 145 | -e 's.-COLON-.:.g' \ |
| 143 | -e 's.-PIPE-.|.g' | 146 | -e 's.-PIPE-.|.g' |
| 144 | } | 147 | } |
| 145 | 148 | ||
| 146 | -antigen-ensure-repo () { | 149 | -antigen-ensure-repo () { |
| 147 | 150 | ||
| 148 | # Ensure that a clone exists for the given repo url and branch. If the first | 151 | # Ensure that a clone exists for the given repo url and branch. If the first |
| 149 | # argument is `--update` and if a clone already exists for the given repo | 152 | # argument is `--update` and if a clone already exists for the given repo |
| 150 | # and branch, it is pull-ed, i.e., updated. | 153 | # and branch, it is pull-ed, i.e., updated. |
| 151 | 154 | ||
| 152 | # Argument defaults. | 155 | # Argument defaults. |
| 153 | # Check if we have to update. | 156 | # Check if we have to update. |
| 154 | local update=false | 157 | local update=false |
| 155 | # Verbose output. | 158 | # Verbose output. |
| 156 | local verbose=false | 159 | local verbose=false |
| 157 | 160 | ||
| 158 | # Load any boolean arguments specified. | 161 | # Load any boolean arguments specified. |
| 159 | while [[ $1 == --* ]]; do | 162 | while [[ $1 == --* ]]; do |
| 160 | eval "local '${1#--}=true'" | 163 | eval "local '${1#--}=true'" |
| 161 | shift | 164 | shift |
| 162 | done | 165 | done |
| 163 | 166 | ||
| 164 | # Get the clone's directory as per the given repo url and branch. | 167 | # Get the clone's directory as per the given repo url and branch. |
| 165 | local url="$1" | 168 | local url="$1" |
| 166 | local clone_dir="$(-antigen-get-clone-dir $url)" | 169 | local clone_dir="$(-antigen-get-clone-dir $url)" |
| 167 | 170 | ||
| 168 | # Clone if it doesn't already exist. | 171 | # Clone if it doesn't already exist. |
| 169 | if [[ ! -d $clone_dir ]]; then | 172 | if [[ ! -d $clone_dir ]]; then |
| 170 | git clone "${url%|*}" "$clone_dir" | 173 | git clone "${url%|*}" "$clone_dir" |
| 171 | elif $update; then | 174 | elif $update; then |
| 172 | # Save current revision. | 175 | # Save current revision. |
| 173 | old_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | 176 | old_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ |
| 174 | rev-parse HEAD)" | 177 | rev-parse HEAD)" |
| 175 | # Pull changes if update requested. | 178 | # Pull changes if update requested. |
| 176 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | 179 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ |
| 177 | pull | 180 | pull |
| 178 | # Get the new revision. | 181 | # Get the new revision. |
| 179 | new_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | 182 | new_rev="$(git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ |
| 180 | rev-parse HEAD)" | 183 | rev-parse HEAD)" |
| 181 | fi | 184 | fi |
| 182 | 185 | ||
| 183 | # If its a specific branch that we want, checkout that branch. | 186 | # If its a specific branch that we want, checkout that branch. |
| 184 | if [[ $url == *\|* ]]; then | 187 | if [[ $url == *\|* ]]; then |
| 185 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | 188 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ |
| 186 | checkout "${url#*|}" | 189 | checkout "${url#*|}" |
| 187 | fi | 190 | fi |
| 188 | 191 | ||
| 189 | if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then | 192 | if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then |
| 190 | echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. | 193 | echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. |
| 191 | if $verbose; then | 194 | if $verbose; then |
| 192 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ | 195 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ |
| 193 | log --oneline --reverse --no-merges --stat '@{1}..' | 196 | log --oneline --reverse --no-merges --stat '@{1}..' |
| 194 | fi | 197 | fi |
| 195 | fi | 198 | fi |
| 196 | 199 | ||
| 197 | } | 200 | } |
| 198 | 201 | ||
| 199 | -antigen-load () { | 202 | -antigen-load () { |
| 200 | 203 | ||
| 201 | local url="$1" | 204 | local url="$1" |
| 202 | local loc="$2" | 205 | local loc="$2" |
| 203 | local btype="$3" | 206 | local btype="$3" |
| 207 | local no_local_clone="$4" | ||
| 204 | 208 | ||
| 205 | # The full location where the plugin is located. | 209 | # The full location where the plugin is located. |
| 206 | local location="$(-antigen-get-clone-dir "$url")/$loc" | 210 | local location |
| 211 | if ! [[ $url == /* && $no_local_clone == true ]]; then | ||
| 212 | location="$(-antigen-get-clone-dir "$url")/$loc" | ||
| 213 | else | ||
| 214 | location="$url" | ||
| 215 | fi | ||
| 207 | 216 | ||
| 208 | if [[ $btype == theme ]]; then | 217 | if [[ $btype == theme ]]; then |
| 209 | 218 | ||
| 210 | # Of course, if its a theme, the location would point to the script | 219 | # Of course, if its a theme, the location would point to the script |
| 211 | # file. | 220 | # file. |
| 212 | source "$location" | 221 | source "$location" |
| 213 | 222 | ||
| 214 | else | 223 | else |
| 215 | 224 | ||
| 216 | # Source the plugin script | 225 | # Source the plugin script |
| 217 | # FIXME: I don't know. Looks very very ugly. Needs a better | 226 | # FIXME: I don't know. Looks very very ugly. Needs a better |
| 218 | # implementation once tests are ready. | 227 | # implementation once tests are ready. |
| 219 | local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" | 228 | local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" |
| 220 | 229 | ||
| 221 | if [[ -f $script_loc ]]; then | 230 | if [[ -f $script_loc ]]; then |
| 222 | # If we have a `*.plugin.zsh`, source it. | 231 | # If we have a `*.plugin.zsh`, source it. |
| 223 | source "$script_loc" | 232 | source "$script_loc" |
| 224 | 233 | ||
| 225 | elif [[ ! -z "$(ls "$location" | grep -m1 '\.zsh$')" ]]; then | 234 | elif [[ ! -z "$(ls "$location" | grep -m1 '\.zsh$')" ]]; then |
| 226 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` | 235 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` |
| 227 | # files. | 236 | # files. |
| 228 | for script ($location/*.zsh(N)) source "$script" | 237 | for script ($location/*.zsh(N)) source "$script" |
| 229 | 238 | ||
| 230 | elif [[ ! -z "$(ls "$location" | grep -m1 '\.sh$')" ]]; then | 239 | elif [[ ! -z "$(ls "$location" | grep -m1 '\.sh$')" ]]; then |
| 231 | # If there are no `*.zsh` files either, we look for and source any | 240 | # If there are no `*.zsh` files either, we look for and source any |
| 232 | # `*.sh` files instead. | 241 | # `*.sh` files instead. |
| 233 | for script ($location/*.sh(N)) source "$script" | 242 | for script ($location/*.sh(N)) source "$script" |
| 234 | 243 | ||
| 235 | fi | 244 | fi |
| 236 | 245 | ||
| 237 | # Add to $fpath, for completion(s). | 246 | # Add to $fpath, for completion(s). |
| 238 | fpath=($location $fpath) | 247 | fpath=($location $fpath) |
| 239 | 248 | ||
| 240 | fi | 249 | fi |
| 241 | 250 | ||
| 242 | } | 251 | } |
| 243 | 252 | ||
| 244 | antigen-cleanup () { | 253 | antigen-cleanup () { |
| 245 | 254 | ||
| 246 | # Cleanup unused repositories. | 255 | # Cleanup unused repositories. |
| 247 | 256 | ||
| 248 | local force=false | 257 | local force=false |
| 249 | if [[ $1 == --force ]]; then | 258 | if [[ $1 == --force ]]; then |
| 250 | force=true | 259 | force=true |
| 251 | fi | 260 | fi |
| 252 | 261 | ||
| 253 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then | 262 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then |
| 254 | echo "You don't have any bundles." | 263 | echo "You don't have any bundles." |
| 255 | return 0 | 264 | return 0 |
| 256 | fi | 265 | fi |
| 257 | 266 | ||
| 258 | # Find directores in ADOTDIR/repos, that are not in the bundles record. | 267 | # Find directores in ADOTDIR/repos, that are not in the bundles record. |
| 259 | local unused_clones="$(comm -13 \ | 268 | local unused_clones="$(comm -13 \ |
| 260 | <(-antigen-echo-record \ | 269 | <(-antigen-echo-record \ |
| 261 | | awk '{print $1}' \ | 270 | | awk '{print $1}' \ |
| 262 | | while read line; do | 271 | | while read line; do |
| 263 | -antigen-get-clone-dir "$line" | 272 | -antigen-get-clone-dir "$line" |
| 264 | done \ | 273 | done \ |
| 265 | | sort -u) \ | 274 | | sort -u) \ |
| 266 | <(ls -d "$ADOTDIR/repos/"* | sort -u))" | 275 | <(ls -d "$ADOTDIR/repos/"* | sort -u))" |
| 267 | 276 | ||
| 268 | if [[ -z $unused_clones ]]; then | 277 | if [[ -z $unused_clones ]]; then |
| 269 | echo "You don't have any unidentified bundles." | 278 | echo "You don't have any unidentified bundles." |
| 270 | return 0 | 279 | return 0 |
| 271 | fi | 280 | fi |
| 272 | 281 | ||
| 273 | echo 'You have clones for the following repos, but are not used.' | 282 | echo 'You have clones for the following repos, but are not used.' |
| 274 | echo "$unused_clones" \ | 283 | echo "$unused_clones" \ |
| 275 | | while read line; do | 284 | | while read line; do |
| 276 | -antigen-get-clone-url "$line" | 285 | -antigen-get-clone-url "$line" |
| 277 | done \ | 286 | done \ |
| 278 | | sed -e 's/^/ /' -e 's/|/, branch /' | 287 | | sed -e 's/^/ /' -e 's/|/, branch /' |
| 279 | 288 | ||
| 280 | if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then | 289 | if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then |
| 281 | echo | 290 | echo |
| 282 | echo | 291 | echo |
| 283 | echo "$unused_clones" | while read line; do | 292 | echo "$unused_clones" | while read line; do |
| 284 | echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." | 293 | echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." |
| 285 | rm -rf "$line" | 294 | rm -rf "$line" |
| 286 | echo ' done.' | 295 | echo ' done.' |
| 287 | done | 296 | done |
| 288 | else | 297 | else |
| 289 | echo | 298 | echo |
| 290 | echo Nothing deleted. | 299 | echo Nothing deleted. |
| 291 | fi | 300 | fi |
| 292 | } | 301 | } |
| 293 | 302 | ||
| 294 | antigen-lib () { | 303 | antigen-lib () { |
| 295 | antigen-bundle --loc=lib | 304 | antigen-bundle --loc=lib |
| 296 | } | 305 | } |
| 297 | 306 | ||
| 298 | antigen-theme () { | 307 | antigen-theme () { |
| 299 | local name="${1:-robbyrussell}" | 308 | local name="${1:-robbyrussell}" |
| 300 | antigen-bundle --loc=themes/$name.zsh-theme --btype=theme | 309 | antigen-bundle --loc=themes/$name.zsh-theme --btype=theme |
| 301 | } | 310 | } |
| 302 | 311 | ||
| 303 | antigen-apply () { | 312 | antigen-apply () { |
| 304 | # Initialize completion. | 313 | # Initialize completion. |
| 305 | # TODO: Only load completions if there are any changes to the bundle | 314 | # TODO: Only load completions if there are any changes to the bundle |
| 306 | # repositories. | 315 | # repositories. |
| 307 | compinit -i | 316 | compinit -i |
| 308 | } | 317 | } |
| 309 | 318 | ||
| 310 | antigen-list () { | 319 | antigen-list () { |
| 311 | # List all currently installed bundles | 320 | # List all currently installed bundles |
| 312 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then | 321 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then |
| 313 | echo "You don't have any bundles." >&2 | 322 | echo "You don't have any bundles." >&2 |
| 314 | return 1 | 323 | return 1 |
| 315 | else | 324 | else |
| 316 | -antigen-echo-record | sort -u | 325 | -antigen-echo-record | sort -u |
| 317 | fi | 326 | fi |
| 318 | } | 327 | } |
| 319 | 328 | ||
| 320 | antigen-help () { | 329 | antigen-help () { |
| 321 | cat <<EOF | 330 | cat <<EOF |
| 322 | Antigen is a plugin management system for zsh. It makes it easy to grab awesome | 331 | Antigen is a plugin management system for zsh. It makes it easy to grab awesome |
| 323 | shell scripts and utilities, put up on github. For further details and complete | 332 | shell scripts and utilities, put up on github. For further details and complete |
| 324 | documentation, visit the project's page at 'http://antigen.sharats.me'. | 333 | documentation, visit the project's page at 'http://antigen.sharats.me'. |
| 325 | EOF | 334 | EOF |
| 326 | } | 335 | } |
| 327 | 336 | ||
| 328 | # A syntax sugar to avoid the `-` when calling antigen commands. With this | 337 | # A syntax sugar to avoid the `-` when calling antigen commands. With this |
| 329 | # function, you can write `antigen-bundle` as `antigen bundle` and so on. | 338 | # function, you can write `antigen-bundle` as `antigen bundle` and so on. |
| 330 | antigen () { | 339 | antigen () { |
| 331 | local cmd="$1" | 340 | local cmd="$1" |
| 332 | shift | 341 | shift |
| 333 | "antigen-$cmd" "$@" | 342 | "antigen-$cmd" "$@" |
| 334 | } | 343 | } |
| 335 | 344 | ||
| 336 | # Echo the bundle specs as in the record. The first line is not echoed since it | 345 | # Echo the bundle specs as in the record. The first line is not echoed since it |
| 337 | # is a blank line. | 346 | # is a blank line. |
| 338 | -antigen-echo-record () { | 347 | -antigen-echo-record () { |
| 339 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' | 348 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' |
| 340 | } | 349 | } |
| 341 | 350 | ||
| 342 | -antigen-env-setup () { | 351 | -antigen-env-setup () { |
| 343 | # Pre-startup initializations | 352 | # Pre-startup initializations |
| 344 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 353 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
| 345 | https://github.com/robbyrussell/oh-my-zsh.git | 354 | https://github.com/robbyrussell/oh-my-zsh.git |
| 346 | -set-default ADOTDIR $HOME/.antigen | 355 | -set-default ADOTDIR $HOME/.antigen |
| 347 | 356 | ||
| 348 | # Load the compinit module | 357 | # Load the compinit module |
| 349 | autoload -U compinit | 358 | autoload -U compinit |
| 350 | 359 | ||
| 351 | # Without the following, `compdef` function is not defined. | 360 | # Without the following, `compdef` function is not defined. |
| 352 | compinit -i | 361 | compinit -i |
| 353 | } | 362 | } |
| 354 | 363 | ||
| 355 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is | 364 | # Same as `export $1=$2`, but will only happen if the name specified by `$1` is |
| 356 | # not already set. | 365 | # not already set. |
| 357 | -set-default () { | 366 | -set-default () { |
| 358 | local arg_name="$1" | 367 | local arg_name="$1" |
| 359 | local arg_value="$2" | 368 | local arg_value="$2" |
| 360 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 369 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
| 361 | } | 370 | } |
| 362 | 371 | ||
| 363 | -antigen-env-setup | 372 | -antigen-env-setup |
| 364 | 373 |
tests/cleanup.t
| 1 | Load a plugin. | 1 | Load a plugin. |
| 2 | 2 | ||
| 3 | $ antigen-bundle $PLUGIN_DIR | 3 | $ antigen-bundle $PLUGIN_DIR |
| 4 | Cloning into '*'... (glob) | 4 | Cloning into '*'... (glob) |
| 5 | done. | 5 | done. |
| 6 | 6 | ||
| 7 | Check the listing. | 7 | Check the listing. |
| 8 | 8 | ||
| 9 | $ antigen-list | 9 | $ antigen-list |
| 10 | */test-plugin / plugin (glob) | 10 | */test-plugin / plugin false (glob) |
| 11 | 11 | ||
| 12 | Clear out the bundles record. | 12 | Clear out the bundles record. |
| 13 | 13 | ||
| 14 | $ _ANTIGEN_BUNDLE_RECORD="" | 14 | $ _ANTIGEN_BUNDLE_RECORD="" |
| 15 | 15 | ||
| 16 | Check the listing, after clearing the record. | 16 | Check the listing, after clearing the record. |
| 17 | 17 | ||
| 18 | $ antigen-list | 18 | $ antigen-list |
| 19 | You don't have any bundles. | 19 | You don't have any bundles. |
| 20 | [1] | 20 | [1] |
| 21 | 21 | ||
| 22 | Confirm the plugin directory exists. | 22 | Confirm the plugin directory exists. |
| 23 | 23 | ||
| 24 | $ ls dot-antigen/repos | wc -l | 24 | $ ls dot-antigen/repos | wc -l |
| 25 | 1 | 25 | 1 |
| 26 | 26 | ||
| 27 | Do the cleanup. | 27 | Do the cleanup. |
| 28 | 28 | ||
| 29 | $ antigen-cleanup --force | 29 | $ antigen-cleanup --force |
| 30 | You have clones for the following repos, but are not used. | 30 | You have clones for the following repos, but are not used. |
| 31 | */test-plugin (glob) | 31 | */test-plugin (glob) |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | Deleting clone for */test-plugin... done. (glob) | 34 | Deleting clone for */test-plugin... done. (glob) |
| 35 | 35 | ||
| 36 | Check the listing, after cleanup. | 36 | Check the listing, after cleanup. |
| 37 | 37 | ||
| 38 | $ antigen-list | 38 | $ antigen-list |
| 39 | You don't have any bundles. | 39 | You don't have any bundles. |
| 40 | [1] | 40 | [1] |
| 41 | 41 | ||
| 42 | Confirm the plugin directory does not exist after cleanup. | 42 | Confirm the plugin directory does not exist after cleanup. |
| 43 | 43 | ||
| 44 | $ ls dot-antigen/repos | wc -l | 44 | $ ls dot-antigen/repos | wc -l |
| 45 | 0 | 45 | 0 |
| 46 | 46 |
tests/list.t
| 1 | Empty initial listing. | 1 | Empty initial listing. |
| 2 | 2 | ||
| 3 | $ antigen-list | 3 | $ antigen-list |
| 4 | You don't have any bundles. | 4 | You don't have any bundles. |
| 5 | [1] | 5 | [1] |
| 6 | 6 | ||
| 7 | Add a bundle. | 7 | Add a bundle. |
| 8 | 8 | ||
| 9 | $ antigen-bundle $PLUGIN_DIR | 9 | $ antigen-bundle $PLUGIN_DIR |
| 10 | Cloning into '.+?'\.\.\. (re) | 10 | Cloning into '.+?'\.\.\. (re) |
| 11 | done. | 11 | done. |
| 12 | $ antigen-list | 12 | $ antigen-list |
| 13 | .*?/test-plugin / plugin (re) | 13 | */test-plugin / plugin false (glob) |
| 14 | 14 | ||
| 15 | Add same bundle and check uniqueness. | 15 | Add same bundle and check uniqueness. |
| 16 | 16 | ||
| 17 | $ antigen-bundle $PLUGIN_DIR | 17 | $ antigen-bundle $PLUGIN_DIR |
| 18 | $ antigen-list | 18 | $ antigen-list |
| 19 | .*?/test-plugin / plugin (re) | 19 | */test-plugin / plugin false (glob) |
| 20 | 20 | ||
| 21 | Add another bundle. | 21 | Add another bundle. |
| 22 | 22 | ||
| 23 | $ antigen-bundle $PLUGIN_DIR2 | 23 | $ antigen-bundle $PLUGIN_DIR2 |
| 24 | Cloning into '.+?'\.\.\. (re) | 24 | Cloning into '.+?'\.\.\. (re) |
| 25 | done. | 25 | done. |
| 26 | $ antigen-list | 26 | $ antigen-list |
| 27 | .*?/test-plugin / plugin (re) | 27 | */test-plugin / plugin false (glob) |
| 28 | .*?/test-plugin2 / plugin (re) | 28 | */test-plugin2 / plugin false (glob) |
| 29 | 29 |