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