Commit 56ae2d04d9b1a4d4359a88c4d7103d09f68ef248
1 parent
dc9be95099
Modified some conditional expressions (with DeMorgan's Law) to fix syntax errors on some shells
Showing 1 changed file with 14 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>, <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 | local _ANTIGEN_INSTALL_DIR="$(dirname $0)" | 8 | local _ANTIGEN_INSTALL_DIR="$(dirname $0)" |
| 9 | 9 | ||
| 10 | # Syntaxes | 10 | # Syntaxes |
| 11 | # antigen-bundle <url> [<loc>=/] | 11 | # antigen-bundle <url> [<loc>=/] |
| 12 | # Keyword only arguments: | 12 | # Keyword only arguments: |
| 13 | # branch - The branch of the repo to use for this bundle. | 13 | # branch - The branch of the repo to use for this bundle. |
| 14 | antigen-bundle () { | 14 | antigen-bundle () { |
| 15 | 15 | ||
| 16 | # Bundle spec arguments' default values. | 16 | # Bundle spec arguments' default values. |
| 17 | local url="$ANTIGEN_DEFAULT_REPO_URL" | 17 | local url="$ANTIGEN_DEFAULT_REPO_URL" |
| 18 | local loc=/ | 18 | local loc=/ |
| 19 | local branch= | 19 | local branch= |
| 20 | local no_local_clone=false | 20 | local no_local_clone=false |
| 21 | local btype=plugin | 21 | local btype=plugin |
| 22 | 22 | ||
| 23 | # Parse the given arguments. (Will overwrite the above values). | 23 | # Parse the given arguments. (Will overwrite the above values). |
| 24 | eval "$(-antigen-parse-args \ | 24 | eval "$(-antigen-parse-args \ |
| 25 | 'url?, loc? ; branch:?, no-local-clone?, btype:?' \ | 25 | 'url?, loc? ; branch:?, no-local-clone?, btype:?' \ |
| 26 | "$@")" | 26 | "$@")" |
| 27 | 27 | ||
| 28 | # Check if url is just the plugin name. Super short syntax. | 28 | # Check if url is just the plugin name. Super short syntax. |
| 29 | if [[ "$url" != */* ]]; then | 29 | if [[ "$url" != */* ]]; then |
| 30 | loc="plugins/$url" | 30 | loc="plugins/$url" |
| 31 | url="$ANTIGEN_DEFAULT_REPO_URL" | 31 | url="$ANTIGEN_DEFAULT_REPO_URL" |
| 32 | fi | 32 | fi |
| 33 | 33 | ||
| 34 | # Resolve the url. | 34 | # Resolve the url. |
| 35 | url="$(-antigen-resolve-bundle-url "$url")" | 35 | url="$(-antigen-resolve-bundle-url "$url")" |
| 36 | 36 | ||
| 37 | # Add the branch information to the url. | 37 | # Add the branch information to the url. |
| 38 | if [[ ! -z $branch ]]; then | 38 | if [[ ! -z $branch ]]; then |
| 39 | url="$url|$branch" | 39 | url="$url|$branch" |
| 40 | fi | 40 | fi |
| 41 | 41 | ||
| 42 | # The `make_local_clone` variable better represents whether there should be | 42 | # The `make_local_clone` variable better represents whether there should be |
| 43 | # a local clone made. For cloning to be avoided, firstly, the `$url` should | 43 | # a local clone made. For cloning to be avoided, firstly, the `$url` should |
| 44 | # be an absolute local path and `$branch` should be empty. In addition to | 44 | # be an absolute local path and `$branch` should be empty. In addition to |
| 45 | # these two conditions, either the `--no-local-clone` option should be | 45 | # these two conditions, either the `--no-local-clone` option should be |
| 46 | # given, or `$url` should not a git repo. | 46 | # given, or `$url` should not a git repo. |
| 47 | local make_local_clone=true | 47 | local make_local_clone=true |
| 48 | if [[ $url == /* && -z $branch && | 48 | if [[ $url == /* && -z $branch && |
| 49 | ( $no_local_clone == true || ! -d $url/.git ) ]]; then | 49 | ( $no_local_clone == true || ! -d $url/.git ) ]]; then |
| 50 | make_local_clone=false | 50 | make_local_clone=false |
| 51 | fi | 51 | fi |
| 52 | 52 | ||
| 53 | # Add the theme extension to `loc`, if this is a theme. | 53 | # Add the theme extension to `loc`, if this is a theme. |
| 54 | if [[ $btype == theme && $loc != *.zsh-theme ]]; then | 54 | if [[ $btype == theme && $loc != *.zsh-theme ]]; then |
| 55 | loc="$loc.zsh-theme" | 55 | loc="$loc.zsh-theme" |
| 56 | fi | 56 | fi |
| 57 | 57 | ||
| 58 | # Add it to the record. | 58 | # Add it to the record. |
| 59 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" | 59 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype" |
| 60 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD $make_local_clone" | 60 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD $make_local_clone" |
| 61 | 61 | ||
| 62 | # Ensure a clone exists for this repo, if needed. | 62 | # Ensure a clone exists for this repo, if needed. |
| 63 | if $make_local_clone; then | 63 | if $make_local_clone; then |
| 64 | -antigen-ensure-repo "$url" | 64 | -antigen-ensure-repo "$url" |
| 65 | fi | 65 | fi |
| 66 | 66 | ||
| 67 | # Load the plugin. | 67 | # Load the plugin. |
| 68 | -antigen-load "$url" "$loc" "$btype" "$make_local_clone" | 68 | -antigen-load "$url" "$loc" "$btype" "$make_local_clone" |
| 69 | 69 | ||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | -antigen-resolve-bundle-url () { | 72 | -antigen-resolve-bundle-url () { |
| 73 | # Given an acceptable short/full form of a bundle's repo url, this function | 73 | # Given an acceptable short/full form of a bundle's repo url, this function |
| 74 | # echoes the full form of the repo's clone url. | 74 | # echoes the full form of the repo's clone url. |
| 75 | 75 | ||
| 76 | local url="$1" | 76 | local url="$1" |
| 77 | 77 | ||
| 78 | # Expand short github url syntax: `username/reponame`. | 78 | # Expand short github url syntax: `username/reponame`. |
| 79 | if [[ $url != git://* && | 79 | if [[ $url != git://* && |
| 80 | $url != https://* && | 80 | $url != https://* && |
| 81 | $url != /* && | 81 | $url != /* && |
| 82 | $url != git@github.com:*/* | 82 | $url != git@github.com:*/* |
| 83 | ]]; then | 83 | ]]; then |
| 84 | url="https://github.com/${url%.git}.git" | 84 | url="https://github.com/${url%.git}.git" |
| 85 | fi | 85 | fi |
| 86 | 86 | ||
| 87 | echo "$url" | 87 | echo "$url" |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | antigen-bundles () { | 90 | antigen-bundles () { |
| 91 | # Bulk add many bundles at one go. Empty lines and lines starting with a `#` | 91 | # Bulk add many bundles at one go. Empty lines and lines starting with a `#` |
| 92 | # are ignored. Everything else is given to `antigen-bundle` as is, no | 92 | # are ignored. Everything else is given to `antigen-bundle` as is, no |
| 93 | # quoting rules applied. | 93 | # quoting rules applied. |
| 94 | 94 | ||
| 95 | local line | 95 | local line |
| 96 | 96 | ||
| 97 | grep -v '^\s*$\|^#' | while read line; do | 97 | grep -v '^\s*$\|^#' | while read line; do |
| 98 | # Using `eval` so that we can use the shell-style quoting in each line | 98 | # Using `eval` so that we can use the shell-style quoting in each line |
| 99 | # piped to `antigen-bundles`. | 99 | # piped to `antigen-bundles`. |
| 100 | eval "antigen-bundle $line" | 100 | eval "antigen-bundle $line" |
| 101 | done | 101 | done |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | antigen-update () { | 104 | antigen-update () { |
| 105 | # Update your bundles, i.e., `git pull` in all the plugin repos. | 105 | # Update your bundles, i.e., `git pull` in all the plugin repos. |
| 106 | 106 | ||
| 107 | date > $ADOTDIR/revert-info | 107 | date > $ADOTDIR/revert-info |
| 108 | 108 | ||
| 109 | -antigen-echo-record | | 109 | -antigen-echo-record | |
| 110 | awk '$4 == "true" {print $1}' | | 110 | awk '$4 == "true" {print $1}' | |
| 111 | sort -u | | 111 | sort -u | |
| 112 | while read url; do | 112 | while read url; do |
| 113 | echo "**** Pulling $url" | 113 | echo "**** Pulling $url" |
| 114 | 114 | ||
| 115 | local clone_dir="$(-antigen-get-clone-dir "$url")" | 115 | local clone_dir="$(-antigen-get-clone-dir "$url")" |
| 116 | if [[ -d "$clone_dir" ]]; then | 116 | if [[ -d "$clone_dir" ]]; then |
| 117 | (echo -n "$clone_dir:" | 117 | (echo -n "$clone_dir:" |
| 118 | cd "$clone_dir" | 118 | cd "$clone_dir" |
| 119 | git rev-parse HEAD) >> $ADOTDIR/revert-info | 119 | git rev-parse HEAD) >> $ADOTDIR/revert-info |
| 120 | fi | 120 | fi |
| 121 | 121 | ||
| 122 | -antigen-ensure-repo "$url" --update --verbose | 122 | -antigen-ensure-repo "$url" --update --verbose |
| 123 | 123 | ||
| 124 | echo | 124 | echo |
| 125 | done | 125 | done |
| 126 | } | 126 | } |
| 127 | 127 | ||
| 128 | antigen-revert () { | 128 | antigen-revert () { |
| 129 | if ! [[ -f $ADOTDIR/revert-info ]]; then | 129 | if [[ -f $ADOTDIR/revert-info ]]; then |
| 130 | cat $ADOTDIR/revert-info | sed '1!p' | while read line; do | ||
| 131 | dir="$(echo "$line" | cut -d: -f1)" | ||
| 132 | git --git-dir="$dir/.git" --work-tree="$dir" \ | ||
| 133 | checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null | ||
| 134 | |||
| 135 | done | ||
| 136 | |||
| 137 | echo "Reverted to state before running -update on $( | ||
| 138 | cat $ADOTDIR/revert-info | sed -n 1p)." | ||
| 139 | |||
| 140 | else | ||
| 130 | echo 'No revert information available. Cannot revert.' >&2 | 141 | echo 'No revert information available. Cannot revert.' >&2 |
| 131 | fi | 142 | fi |
| 132 | 143 | ||
| 133 | cat $ADOTDIR/revert-info | sed '1!p' | while read line; do | ||
| 134 | dir="$(echo "$line" | cut -d: -f1)" | ||
| 135 | git --git-dir="$dir/.git" --work-tree="$dir" \ | ||
| 136 | checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null | ||
| 137 | done | ||
| 138 | 144 | ||
| 139 | echo "Reverted to state before running -update on $( | ||
| 140 | cat $ADOTDIR/revert-info | sed -n 1p)." | ||
| 141 | } | 145 | } |
| 142 | 146 | ||
| 143 | -antigen-get-clone-dir () { | 147 | -antigen-get-clone-dir () { |
| 144 | # Takes a repo url and gives out the path that this url needs to be cloned | 148 | # Takes a repo url and gives out the path that this url needs to be cloned |
| 145 | # to. Doesn't actually clone anything. | 149 | # to. Doesn't actually clone anything. |
| 146 | echo -n $ADOTDIR/repos/ | 150 | echo -n $ADOTDIR/repos/ |
| 147 | 151 | ||
| 148 | if [[ "$1" == "https://github.com/sorin-ionescu/prezto.git" ]]; then | 152 | if [[ "$1" == "https://github.com/sorin-ionescu/prezto.git" ]]; then |
| 149 | # Prezto's directory *has* to be `.zprezto`. | 153 | # Prezto's directory *has* to be `.zprezto`. |
| 150 | echo .zprezto | 154 | echo .zprezto |
| 151 | 155 | ||
| 152 | else | 156 | else |
| 153 | echo "$1" | sed \ | 157 | echo "$1" | sed \ |
| 154 | -e 's./.-SLASH-.g' \ | 158 | -e 's./.-SLASH-.g' \ |
| 155 | -e 's.:.-COLON-.g' \ | 159 | -e 's.:.-COLON-.g' \ |
| 156 | -e 's.|.-PIPE-.g' | 160 | -e 's.|.-PIPE-.g' |
| 157 | 161 | ||
| 158 | fi | 162 | fi |
| 159 | } | 163 | } |
| 160 | 164 | ||
| 161 | -antigen-get-clone-url () { | 165 | -antigen-get-clone-url () { |
| 162 | # Takes a repo's clone dir and gives out the repo's original url that was | 166 | # Takes a repo's clone dir and gives out the repo's original url that was |
| 163 | # used to create the given directory path. | 167 | # used to create the given directory path. |
| 164 | 168 | ||
| 165 | if [[ "$1" == ".zprezto" ]]; then | 169 | if [[ "$1" == ".zprezto" ]]; then |
| 166 | # Prezto's (in `.zprezto`), is assumed to be from `sorin-ionescu`'s | 170 | # Prezto's (in `.zprezto`), is assumed to be from `sorin-ionescu`'s |
| 167 | # remote. | 171 | # remote. |
| 168 | echo https://github.com/sorin-ionescu/prezto.git | 172 | echo https://github.com/sorin-ionescu/prezto.git |
| 169 | 173 | ||
| 170 | else | 174 | else |
| 171 | echo "$1" | sed \ | 175 | echo "$1" | sed \ |
| 172 | -e "s:^$ADOTDIR/repos/::" \ | 176 | -e "s:^$ADOTDIR/repos/::" \ |
| 173 | -e 's.-SLASH-./.g' \ | 177 | -e 's.-SLASH-./.g' \ |
| 174 | -e 's.-COLON-.:.g' \ | 178 | -e 's.-COLON-.:.g' \ |
| 175 | -e 's.-PIPE-.|.g' | 179 | -e 's.-PIPE-.|.g' |
| 176 | 180 | ||
| 177 | fi | 181 | fi |
| 178 | } | 182 | } |
| 179 | 183 | ||
| 180 | -antigen-ensure-repo () { | 184 | -antigen-ensure-repo () { |
| 181 | 185 | ||
| 182 | # Ensure that a clone exists for the given repo url and branch. If the first | 186 | # Ensure that a clone exists for the given repo url and branch. If the first |
| 183 | # argument is `--update` and if a clone already exists for the given repo | 187 | # argument is `--update` and if a clone already exists for the given repo |
| 184 | # and branch, it is pull-ed, i.e., updated. | 188 | # and branch, it is pull-ed, i.e., updated. |
| 185 | 189 | ||
| 186 | # Argument defaults. | 190 | # Argument defaults. |
| 187 | # The url. No sane default for this, so just empty. | 191 | # The url. No sane default for this, so just empty. |
| 188 | local url= | 192 | local url= |
| 189 | # Check if we have to update. | 193 | # Check if we have to update. |
| 190 | local update=false | 194 | local update=false |
| 191 | # Verbose output. | 195 | # Verbose output. |
| 192 | local verbose=false | 196 | local verbose=false |
| 193 | 197 | ||
| 194 | eval "$(-antigen-parse-args 'url ; update?, verbose?' "$@")" | 198 | eval "$(-antigen-parse-args 'url ; update?, verbose?' "$@")" |
| 195 | shift $# | 199 | shift $# |
| 196 | 200 | ||
| 197 | # Get the clone's directory as per the given repo url and branch. | 201 | # Get the clone's directory as per the given repo url and branch. |
| 198 | local clone_dir="$(-antigen-get-clone-dir $url)" | 202 | local clone_dir="$(-antigen-get-clone-dir $url)" |
| 199 | 203 | ||
| 200 | # A temporary function wrapping the `git` command with repeated arguments. | 204 | # A temporary function wrapping the `git` command with repeated arguments. |
| 201 | --plugin-git () { | 205 | --plugin-git () { |
| 202 | (cd "$clone_dir" && git --no-pager "$@") | 206 | (cd "$clone_dir" && git --no-pager "$@") |
| 203 | } | 207 | } |
| 204 | 208 | ||
| 205 | # Clone if it doesn't already exist. | 209 | # Clone if it doesn't already exist. |
| 206 | if [[ ! -d $clone_dir ]]; then | 210 | if [[ ! -d $clone_dir ]]; then |
| 207 | git clone --recursive "${url%|*}" "$clone_dir" | 211 | git clone --recursive "${url%|*}" "$clone_dir" |
| 208 | elif $update; then | 212 | elif $update; then |
| 209 | # Save current revision. | 213 | # Save current revision. |
| 210 | local old_rev="$(--plugin-git rev-parse HEAD)" | 214 | local old_rev="$(--plugin-git rev-parse HEAD)" |
| 211 | # Pull changes if update requested. | 215 | # Pull changes if update requested. |
| 212 | --plugin-git pull | 216 | --plugin-git pull |
| 213 | # Update submodules. | 217 | # Update submodules. |
| 214 | --plugin-git submodule update --recursive | 218 | --plugin-git submodule update --recursive |
| 215 | # Get the new revision. | 219 | # Get the new revision. |
| 216 | local new_rev="$(--plugin-git rev-parse HEAD)" | 220 | local new_rev="$(--plugin-git rev-parse HEAD)" |
| 217 | fi | 221 | fi |
| 218 | 222 | ||
| 219 | # If its a specific branch that we want, checkout that branch. | 223 | # If its a specific branch that we want, checkout that branch. |
| 220 | if [[ $url == *\|* ]]; then | 224 | if [[ $url == *\|* ]]; then |
| 221 | local current_branch=${$(--plugin-git symbolic-ref HEAD)##refs/heads/} | 225 | local current_branch=${$(--plugin-git symbolic-ref HEAD)##refs/heads/} |
| 222 | local requested_branch="${url#*|}" | 226 | local requested_branch="${url#*|}" |
| 223 | # Only do the checkout when we are not already on the branch. | 227 | # Only do the checkout when we are not already on the branch. |
| 224 | [[ $requested_branch != $current_branch ]] && | 228 | [[ $requested_branch != $current_branch ]] && |
| 225 | --plugin-git checkout $requested_branch | 229 | --plugin-git checkout $requested_branch |
| 226 | fi | 230 | fi |
| 227 | 231 | ||
| 228 | if ! [[ -z $old_rev || $old_rev == $new_rev ]]; then | 232 | if [[ -n $old_rev && $old_rev != $new_rev ]]; then |
| 229 | echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. | 233 | echo Updated from ${old_rev:0:7} to ${new_rev:0:7}. |
| 230 | if $verbose; then | 234 | if $verbose; then |
| 231 | --plugin-git log --oneline --reverse --no-merges --stat '@{1}..' | 235 | --plugin-git log --oneline --reverse --no-merges --stat '@{1}..' |
| 232 | fi | 236 | fi |
| 233 | fi | 237 | fi |
| 234 | 238 | ||
| 235 | # Remove the temporary git wrapper function. | 239 | # Remove the temporary git wrapper function. |
| 236 | unfunction -- --plugin-git | 240 | unfunction -- --plugin-git |
| 237 | 241 | ||
| 238 | } | 242 | } |
| 239 | 243 | ||
| 240 | -antigen-load () { | 244 | -antigen-load () { |
| 241 | 245 | ||
| 242 | local url="$1" | 246 | local url="$1" |
| 243 | local loc="$2" | 247 | local loc="$2" |
| 244 | local btype="$3" | 248 | local btype="$3" |
| 245 | local make_local_clone="$4" | 249 | local make_local_clone="$4" |
| 246 | 250 | ||
| 247 | # The full location where the plugin is located. | 251 | # The full location where the plugin is located. |
| 248 | local location | 252 | local location |
| 249 | if $make_local_clone; then | 253 | if $make_local_clone; then |
| 250 | location="$(-antigen-get-clone-dir "$url")/$loc" | 254 | location="$(-antigen-get-clone-dir "$url")/$loc" |
| 251 | else | 255 | else |
| 252 | location="$url" | 256 | location="$url" |
| 253 | fi | 257 | fi |
| 254 | 258 | ||
| 255 | if [[ $btype == theme ]]; then | 259 | if [[ $btype == theme ]]; then |
| 256 | 260 | ||
| 257 | # Of course, if its a theme, the location would point to the script | 261 | # Of course, if its a theme, the location would point to the script |
| 258 | # file. | 262 | # file. |
| 259 | source "$location" | 263 | source "$location" |
| 260 | 264 | ||
| 261 | else | 265 | else |
| 262 | 266 | ||
| 263 | # Source the plugin script. | 267 | # Source the plugin script. |
| 264 | # FIXME: I don't know. Looks very very ugly. Needs a better | 268 | # FIXME: I don't know. Looks very very ugly. Needs a better |
| 265 | # implementation once tests are ready. | 269 | # implementation once tests are ready. |
| 266 | local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" | 270 | local script_loc="$(ls "$location" | grep -m1 '\.plugin\.zsh$')" |
| 267 | 271 | ||
| 268 | if [[ -f $location/$script_loc ]]; then | 272 | if [[ -f $location/$script_loc ]]; then |
| 269 | # If we have a `*.plugin.zsh`, source it. | 273 | # If we have a `*.plugin.zsh`, source it. |
| 270 | source "$location/$script_loc" | 274 | source "$location/$script_loc" |
| 271 | 275 | ||
| 272 | elif [[ -f $location/init.zsh ]]; then | 276 | elif [[ -f $location/init.zsh ]]; then |
| 273 | # If we have a `init.zsh` | 277 | # If we have a `init.zsh` |
| 274 | if (( $+functions[pmodload] )); then | 278 | if (( $+functions[pmodload] )); then |
| 275 | # If pmodload is defined pmodload the module. Remove `modules/` | 279 | # If pmodload is defined pmodload the module. Remove `modules/` |
| 276 | # from loc to find module name. | 280 | # from loc to find module name. |
| 277 | pmodload "${loc#modules/}" | 281 | pmodload "${loc#modules/}" |
| 278 | else | 282 | else |
| 279 | # Otherwise source it. | 283 | # Otherwise source it. |
| 280 | source "$location/init.zsh" | 284 | source "$location/init.zsh" |
| 281 | fi | 285 | fi |
| 282 | 286 | ||
| 283 | elif ls "$location" | grep -qm1 '\.zsh$'; then | 287 | elif ls "$location" | grep -qm1 '\.zsh$'; then |
| 284 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` | 288 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` |
| 285 | # files. | 289 | # files. |
| 286 | for script ($location/*.zsh(N)) source "$script" | 290 | for script ($location/*.zsh(N)) source "$script" |
| 287 | 291 | ||
| 288 | elif ls "$location" | grep -qm1 '\.sh$'; then | 292 | elif ls "$location" | grep -qm1 '\.sh$'; then |
| 289 | # If there are no `*.zsh` files either, we look for and source any | 293 | # If there are no `*.zsh` files either, we look for and source any |
| 290 | # `*.sh` files instead. | 294 | # `*.sh` files instead. |
| 291 | for script ($location/*.sh(N)) source "$script" | 295 | for script ($location/*.sh(N)) source "$script" |
| 292 | 296 | ||
| 293 | fi | 297 | fi |
| 294 | 298 | ||
| 295 | # Add to $fpath, for completion(s). | 299 | # Add to $fpath, for completion(s). |
| 296 | fpath=($location $fpath) | 300 | fpath=($location $fpath) |
| 297 | 301 | ||
| 298 | fi | 302 | fi |
| 299 | 303 | ||
| 300 | } | 304 | } |
| 301 | 305 | ||
| 302 | # Update (with `git pull`) antigen itself. | 306 | # Update (with `git pull`) antigen itself. |
| 303 | # TODO: Once update is finished, show a summary of the new commits, as a kind of | 307 | # TODO: Once update is finished, show a summary of the new commits, as a kind of |
| 304 | # "what's new" message. | 308 | # "what's new" message. |
| 305 | antigen-selfupdate () { | 309 | antigen-selfupdate () { |
| 306 | ( cd $_ANTIGEN_INSTALL_DIR | 310 | ( cd $_ANTIGEN_INSTALL_DIR |
| 307 | if [[ ! -d .git ]]; then | 311 | if [[ ! -d .git ]]; then |
| 308 | echo "Your copy of antigen doesn't appear to be a git clone. " \ | 312 | echo "Your copy of antigen doesn't appear to be a git clone. " \ |
| 309 | "The 'selfupdate' command cannot work in this case." | 313 | "The 'selfupdate' command cannot work in this case." |
| 310 | return 1 | 314 | return 1 |
| 311 | fi | 315 | fi |
| 312 | git pull | 316 | git pull |
| 313 | ) | 317 | ) |
| 314 | } | 318 | } |
| 315 | 319 | ||
| 316 | antigen-cleanup () { | 320 | antigen-cleanup () { |
| 317 | 321 | ||
| 318 | # Cleanup unused repositories. | 322 | # Cleanup unused repositories. |
| 319 | 323 | ||
| 320 | local force=false | 324 | local force=false |
| 321 | if [[ $1 == --force ]]; then | 325 | if [[ $1 == --force ]]; then |
| 322 | force=true | 326 | force=true |
| 323 | fi | 327 | fi |
| 324 | 328 | ||
| 325 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then | 329 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then |
| 326 | echo "You don't have any bundles." | 330 | echo "You don't have any bundles." |
| 327 | return 0 | 331 | return 0 |
| 328 | fi | 332 | fi |
| 329 | 333 | ||
| 330 | # Find directores in ADOTDIR/repos, that are not in the bundles record. | 334 | # Find directores in ADOTDIR/repos, that are not in the bundles record. |
| 331 | local unused_clones="$(comm -13 \ | 335 | local unused_clones="$(comm -13 \ |
| 332 | <(-antigen-echo-record | | 336 | <(-antigen-echo-record | |
| 333 | awk '$4 == "true" {print $1}' | | 337 | awk '$4 == "true" {print $1}' | |
| 334 | while read line; do | 338 | while read line; do |
| 335 | -antigen-get-clone-dir "$line" | 339 | -antigen-get-clone-dir "$line" |
| 336 | done | | 340 | done | |
| 337 | sort -u) \ | 341 | sort -u) \ |
| 338 | <(ls -d "$ADOTDIR/repos/"* | sort -u))" | 342 | <(ls -d "$ADOTDIR/repos/"* | sort -u))" |
| 339 | 343 | ||
| 340 | if [[ -z $unused_clones ]]; then | 344 | if [[ -z $unused_clones ]]; then |
| 341 | echo "You don't have any unidentified bundles." | 345 | echo "You don't have any unidentified bundles." |
| 342 | return 0 | 346 | return 0 |
| 343 | fi | 347 | fi |
| 344 | 348 | ||
| 345 | echo 'You have clones for the following repos, but are not used.' | 349 | echo 'You have clones for the following repos, but are not used.' |
| 346 | echo "$unused_clones" | | 350 | echo "$unused_clones" | |
| 347 | while read line; do | 351 | while read line; do |
| 348 | -antigen-get-clone-url "$line" | 352 | -antigen-get-clone-url "$line" |
| 349 | done | | 353 | done | |
| 350 | sed -e 's/^/ /' -e 's/|/, branch /' | 354 | sed -e 's/^/ /' -e 's/|/, branch /' |
| 351 | 355 | ||
| 352 | if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then | 356 | if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then |
| 353 | echo | 357 | echo |
| 354 | echo | 358 | echo |
| 355 | echo "$unused_clones" | while read line; do | 359 | echo "$unused_clones" | while read line; do |
| 356 | echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." | 360 | echo -n "Deleting clone for $(-antigen-get-clone-url "$line")..." |
| 357 | rm -rf "$line" | 361 | rm -rf "$line" |
| 358 | echo ' done.' | 362 | echo ' done.' |
| 359 | done | 363 | done |
| 360 | else | 364 | else |
| 361 | echo | 365 | echo |
| 362 | echo Nothing deleted. | 366 | echo Nothing deleted. |
| 363 | fi | 367 | fi |
| 364 | } | 368 | } |
| 365 | 369 | ||
| 366 | antigen-lib () { | 370 | antigen-lib () { |
| 367 | if [[ -z "$ZSH" ]]; then | 371 | if [[ -z "$ZSH" ]]; then |
| 368 | export ZSH="$(-antigen-get-clone-dir "$ANTIGEN_DEFAULT_REPO_URL")" | 372 | export ZSH="$(-antigen-get-clone-dir "$ANTIGEN_DEFAULT_REPO_URL")" |
| 369 | fi | 373 | fi |
| 370 | antigen-bundle --loc=lib | 374 | antigen-bundle --loc=lib |
| 371 | } | 375 | } |
| 372 | 376 | ||
| 373 | antigen-prezto-lib () { | 377 | antigen-prezto-lib () { |
| 374 | antigen-bundle sorin-ionescu/prezto | 378 | antigen-bundle sorin-ionescu/prezto |
| 375 | export ZDOTDIR=$ADOTDIR/repos/ | 379 | export ZDOTDIR=$ADOTDIR/repos/ |
| 376 | } | 380 | } |
| 377 | 381 | ||
| 378 | antigen-theme () { | 382 | antigen-theme () { |
| 379 | 383 | ||
| 380 | if [[ "$1" != */* && "$1" != --* ]]; then | 384 | if [[ "$1" != */* && "$1" != --* ]]; then |
| 381 | # The first argument is just a name of the plugin, to be picked up from | 385 | # The first argument is just a name of the plugin, to be picked up from |
| 382 | # the default repo. | 386 | # the default repo. |
| 383 | local name="${1:-robbyrussell}" | 387 | local name="${1:-robbyrussell}" |
| 384 | antigen-bundle --loc=themes/$name --btype=theme | 388 | antigen-bundle --loc=themes/$name --btype=theme |
| 385 | 389 | ||
| 386 | else | 390 | else |
| 387 | antigen-bundle "$@" --btype=theme | 391 | antigen-bundle "$@" --btype=theme |
| 388 | 392 | ||
| 389 | fi | 393 | fi |
| 390 | 394 | ||
| 391 | } | 395 | } |
| 392 | 396 | ||
| 393 | antigen-apply () { | 397 | antigen-apply () { |
| 394 | # Initialize completion. | 398 | # Initialize completion. |
| 395 | # TODO: Only load completions if there are any changes to the bundle | 399 | # TODO: Only load completions if there are any changes to the bundle |
| 396 | # repositories. | 400 | # repositories. |
| 397 | compinit -i | 401 | compinit -i |
| 398 | } | 402 | } |
| 399 | 403 | ||
| 400 | antigen-list () { | 404 | antigen-list () { |
| 401 | # List all currently installed bundles. | 405 | # List all currently installed bundles. |
| 402 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then | 406 | if [[ -z "$_ANTIGEN_BUNDLE_RECORD" ]]; then |
| 403 | echo "You don't have any bundles." >&2 | 407 | echo "You don't have any bundles." >&2 |
| 404 | return 1 | 408 | return 1 |
| 405 | else | 409 | else |
| 406 | -antigen-echo-record | sort -u | 410 | -antigen-echo-record | sort -u |
| 407 | fi | 411 | fi |
| 408 | } | 412 | } |
| 409 | 413 | ||
| 410 | antigen-snapshot () { | 414 | antigen-snapshot () { |
| 411 | 415 | ||
| 412 | local snapshot_file="${1:-antigen-shapshot}" | 416 | local snapshot_file="${1:-antigen-shapshot}" |
| 413 | 417 | ||
| 414 | # The snapshot content lines are pairs of repo-url and git version hash, in | 418 | # The snapshot content lines are pairs of repo-url and git version hash, in |
| 415 | # the form: | 419 | # the form: |
| 416 | # <version-hash> <repo-url> | 420 | # <version-hash> <repo-url> |
| 417 | local snapshot_content="$(-antigen-echo-record | | 421 | local snapshot_content="$(-antigen-echo-record | |
| 418 | grep 'true$' | | 422 | grep 'true$' | |
| 419 | sed 's/ .*$//' | | 423 | sed 's/ .*$//' | |
| 420 | sort -u | | 424 | sort -u | |
| 421 | while read url; do | 425 | while read url; do |
| 422 | local dir="$(-antigen-get-clone-dir "$url")" | 426 | local dir="$(-antigen-get-clone-dir "$url")" |
| 423 | local version_hash="$(cd "$dir" && git rev-parse HEAD)" | 427 | local version_hash="$(cd "$dir" && git rev-parse HEAD)" |
| 424 | echo "$version_hash $url" | 428 | echo "$version_hash $url" |
| 425 | done)" | 429 | done)" |
| 426 | 430 | ||
| 427 | { | 431 | { |
| 428 | # The first line in the snapshot file is for metadata, in the form: | 432 | # The first line in the snapshot file is for metadata, in the form: |
| 429 | # key='value'; key='value'; key='value'; | 433 | # key='value'; key='value'; key='value'; |
| 430 | # Where `key`s are valid shell variable names. | 434 | # Where `key`s are valid shell variable names. |
| 431 | 435 | ||
| 432 | # Snapshot version. Has no relation to antigen version. If the snapshot | 436 | # Snapshot version. Has no relation to antigen version. If the snapshot |
| 433 | # file format changes, this number can be incremented. | 437 | # file format changes, this number can be incremented. |
| 434 | echo -n "version='1';" | 438 | echo -n "version='1';" |
| 435 | 439 | ||
| 436 | # Snapshot creation date+time. | 440 | # Snapshot creation date+time. |
| 437 | echo -n " created_on='$(date)';" | 441 | echo -n " created_on='$(date)';" |
| 438 | 442 | ||
| 439 | # Add a checksum with the md5 checksum of all the snapshot lines. | 443 | # Add a checksum with the md5 checksum of all the snapshot lines. |
| 440 | local checksum="$(echo "$snapshot_content" | md5sum)" | 444 | local checksum="$(echo "$snapshot_content" | md5sum)" |
| 441 | echo -n " checksum='${checksum%% *}';" | 445 | echo -n " checksum='${checksum%% *}';" |
| 442 | 446 | ||
| 443 | # A newline after the metadata and then the snapshot lines. | 447 | # A newline after the metadata and then the snapshot lines. |
| 444 | echo "\n$snapshot_content" | 448 | echo "\n$snapshot_content" |
| 445 | 449 | ||
| 446 | } > "$snapshot_file" | 450 | } > "$snapshot_file" |
| 447 | 451 | ||
| 448 | } | 452 | } |
| 449 | 453 | ||
| 450 | antigen-restore () { | 454 | antigen-restore () { |
| 451 | 455 | ||
| 452 | if [[ $# == 0 ]]; then | 456 | if [[ $# == 0 ]]; then |
| 453 | echo 'Please provide a snapshot file to restore from.' >&2 | 457 | echo 'Please provide a snapshot file to restore from.' >&2 |
| 454 | return 1 | 458 | return 1 |
| 455 | fi | 459 | fi |
| 456 | 460 | ||
| 457 | local snapshot_file="$1" | 461 | local snapshot_file="$1" |
| 458 | 462 | ||
| 459 | # TODO: Before doing anything with the snapshot file, verify its checksum. | 463 | # TODO: Before doing anything with the snapshot file, verify its checksum. |
| 460 | # If it fails, notify this to the user and confirm if restore should | 464 | # If it fails, notify this to the user and confirm if restore should |
| 461 | # proceed. | 465 | # proceed. |
| 462 | 466 | ||
| 463 | echo -n "Restoring from $snapshot_file..." | 467 | echo -n "Restoring from $snapshot_file..." |
| 464 | 468 | ||
| 465 | sed -n '1!p' "$snapshot_file" | | 469 | sed -n '1!p' "$snapshot_file" | |
| 466 | while read line; do | 470 | while read line; do |
| 467 | 471 | ||
| 468 | local version_hash="${line%% *}" | 472 | local version_hash="${line%% *}" |
| 469 | local url="${line##* }" | 473 | local url="${line##* }" |
| 470 | local clone_dir="$(-antigen-get-clone-dir "$url")" | 474 | local clone_dir="$(-antigen-get-clone-dir "$url")" |
| 471 | 475 | ||
| 472 | if [[ ! -d $clone_dir ]]; then | 476 | if [[ ! -d $clone_dir ]]; then |
| 473 | git clone "$url" "$clone_dir" > /dev/null | 477 | git clone "$url" "$clone_dir" > /dev/null |
| 474 | fi | 478 | fi |
| 475 | 479 | ||
| 476 | (cd "$clone_dir" && git checkout $version_hash) 2> /dev/null | 480 | (cd "$clone_dir" && git checkout $version_hash) 2> /dev/null |
| 477 | 481 | ||
| 478 | done | 482 | done |
| 479 | 483 | ||
| 480 | echo ' done.' | 484 | echo ' done.' |
| 481 | echo 'Please open a new shell to get the restored changes.' | 485 | echo 'Please open a new shell to get the restored changes.' |
| 482 | } | 486 | } |
| 483 | 487 | ||
| 484 | antigen-help () { | 488 | antigen-help () { |
| 485 | cat <<EOF | 489 | cat <<EOF |
| 486 | Antigen is a plugin management system for zsh. It makes it easy to grab awesome | 490 | Antigen is a plugin management system for zsh. It makes it easy to grab awesome |
| 487 | shell scripts and utilities, put up on github. For further details and complete | 491 | shell scripts and utilities, put up on github. For further details and complete |
| 488 | documentation, visit the project's page at 'http://antigen.sharats.me'. | 492 | documentation, visit the project's page at 'http://antigen.sharats.me'. |
| 489 | EOF | 493 | EOF |
| 490 | } | 494 | } |
| 491 | 495 | ||
| 492 | # A syntax sugar to avoid the `-` when calling antigen commands. With this | 496 | # A syntax sugar to avoid the `-` when calling antigen commands. With this |
| 493 | # function, you can write `antigen-bundle` as `antigen bundle` and so on. | 497 | # function, you can write `antigen-bundle` as `antigen bundle` and so on. |
| 494 | antigen () { | 498 | antigen () { |
| 495 | local cmd="$1" | 499 | local cmd="$1" |
| 496 | shift | 500 | shift |
| 497 | "antigen-$cmd" "$@" | 501 | "antigen-$cmd" "$@" |
| 498 | } | 502 | } |
| 499 | 503 | ||
| 500 | -antigen-parse-args () { | 504 | -antigen-parse-args () { |
| 501 | # An argument parsing functionality to parse arguments the *antigen* way :). | 505 | # An argument parsing functionality to parse arguments the *antigen* way :). |
| 502 | # Takes one first argument (called spec), which dictates how to parse and | 506 | # Takes one first argument (called spec), which dictates how to parse and |
| 503 | # the rest of the arguments are parsed. Outputs a piece of valid shell code | 507 | # the rest of the arguments are parsed. Outputs a piece of valid shell code |
| 504 | # that can be passed to `eval` inside a function which creates the arguments | 508 | # that can be passed to `eval` inside a function which creates the arguments |
| 505 | # and their values as local variables. Suggested use is to set the defaults | 509 | # and their values as local variables. Suggested use is to set the defaults |
| 506 | # to all arguments first and then eval the output of this function. | 510 | # to all arguments first and then eval the output of this function. |
| 507 | 511 | ||
| 508 | # Spec: Only long argument supported. No support for parsing short options. | 512 | # Spec: Only long argument supported. No support for parsing short options. |
| 509 | # The spec must have two sections, separated by a `;`. | 513 | # The spec must have two sections, separated by a `;`. |
| 510 | # '<positional-arguments>;<keyword-only-arguments>' | 514 | # '<positional-arguments>;<keyword-only-arguments>' |
| 511 | # Positional arguments are passed as just values, like `command a b`. | 515 | # Positional arguments are passed as just values, like `command a b`. |
| 512 | # Keyword arguments are passed as a `--name=value` pair, like `command | 516 | # Keyword arguments are passed as a `--name=value` pair, like `command |
| 513 | # --arg1=a --arg2=b`. | 517 | # --arg1=a --arg2=b`. |
| 514 | 518 | ||
| 515 | # Each argument in the spec is separated by a `,`. Each keyword argument can | 519 | # Each argument in the spec is separated by a `,`. Each keyword argument can |
| 516 | # end in a `:` to specifiy that this argument wants a value, otherwise it | 520 | # end in a `:` to specifiy that this argument wants a value, otherwise it |
| 517 | # doesn't take a value. (The value in the output when the keyword argument | 521 | # doesn't take a value. (The value in the output when the keyword argument |
| 518 | # doesn't have a `:` is `true`). | 522 | # doesn't have a `:` is `true`). |
| 519 | 523 | ||
| 520 | # Arguments in either section can end with a `?` (should come after `:`, if | 524 | # Arguments in either section can end with a `?` (should come after `:`, if |
| 521 | # both are present), means optional. FIXME: Not yet implemented. | 525 | # both are present), means optional. FIXME: Not yet implemented. |
| 522 | 526 | ||
| 523 | # See the test file, tests/arg-parser.t for (working) examples. | 527 | # See the test file, tests/arg-parser.t for (working) examples. |
| 524 | 528 | ||
| 525 | local spec="$1" | 529 | local spec="$1" |
| 526 | shift | 530 | shift |
| 527 | 531 | ||
| 528 | # Sanitize the spec | 532 | # Sanitize the spec |
| 529 | spec="$(echo "$spec" | tr '\n' ' ' | sed 's/[[:space:]]//g')" | 533 | spec="$(echo "$spec" | tr '\n' ' ' | sed 's/[[:space:]]//g')" |
| 530 | 534 | ||
| 531 | local code='' | 535 | local code='' |
| 532 | 536 | ||
| 533 | --add-var () { | 537 | --add-var () { |
| 534 | test -z "$code" || code="$code\n" | 538 | test -z "$code" || code="$code\n" |
| 535 | code="${code}local $1='$2'" | 539 | code="${code}local $1='$2'" |
| 536 | } | 540 | } |
| 537 | 541 | ||
| 538 | local positional_args="$(echo "$spec" | cut -d\; -f1)" | 542 | local positional_args="$(echo "$spec" | cut -d\; -f1)" |
| 539 | local positional_args_count="$(echo $positional_args | | 543 | local positional_args_count="$(echo $positional_args | |
| 540 | awk -F, '{print NF}')" | 544 | awk -F, '{print NF}')" |
| 541 | 545 | ||
| 542 | # Set spec values based on the positional arguments. | 546 | # Set spec values based on the positional arguments. |
| 543 | local i=1 | 547 | local i=1 |
| 544 | while ! [[ -z $1 || $1 == --* ]]; do | 548 | while [[ -n $1 && $1 != --* ]]; do |
| 545 | 549 | ||
| 546 | if (( $i > $positional_args_count )); then | 550 | if (( $i > $positional_args_count )); then |
| 547 | echo "Only $positional_args_count positional arguments allowed." >&2 | 551 | echo "Only $positional_args_count positional arguments allowed." >&2 |
| 548 | echo "Found at least one more: '$1'" >&2 | 552 | echo "Found at least one more: '$1'" >&2 |
| 549 | return | 553 | return |
| 550 | fi | 554 | fi |
| 551 | 555 | ||
| 552 | local name_spec="$(echo "$positional_args" | cut -d, -f$i)" | 556 | local name_spec="$(echo "$positional_args" | cut -d, -f$i)" |
| 553 | local name="${${name_spec%\?}%:}" | 557 | local name="${${name_spec%\?}%:}" |
| 554 | local value="$1" | 558 | local value="$1" |
| 555 | 559 | ||
| 556 | if echo "$code" | grep -qm1 "^local $name="; then | 560 | if echo "$code" | grep -qm1 "^local $name="; then |
| 557 | echo "Argument '$name' repeated with the value '$value'". >&2 | 561 | echo "Argument '$name' repeated with the value '$value'". >&2 |
| 558 | return | 562 | return |
| 559 | fi | 563 | fi |
| 560 | 564 | ||
| 561 | --add-var $name "$value" | 565 | --add-var $name "$value" |
| 562 | 566 | ||
| 563 | shift | 567 | shift |
| 564 | i=$(($i + 1)) | 568 | i=$(($i + 1)) |
| 565 | done | 569 | done |
| 566 | 570 | ||
| 567 | local keyword_args="$( | 571 | local keyword_args="$( |
| 568 | # Positional arguments can double up as keyword arguments too. | 572 | # Positional arguments can double up as keyword arguments too. |
| 569 | echo "$positional_args" | tr , '\n' | | 573 | echo "$positional_args" | tr , '\n' | |
| 570 | while read line; do | 574 | while read line; do |
| 571 | if [[ $line == *\? ]]; then | 575 | if [[ $line == *\? ]]; then |
| 572 | echo "${line%?}:?" | 576 | echo "${line%?}:?" |
| 573 | else | 577 | else |
| 574 | echo "$line:" | 578 | echo "$line:" |
| 575 | fi | 579 | fi |
| 576 | done | 580 | done |
| 577 | 581 | ||
| 578 | # Specified keyword arguments. | 582 | # Specified keyword arguments. |
| 579 | echo "$spec" | cut -d\; -f2 | tr , '\n' | 583 | echo "$spec" | cut -d\; -f2 | tr , '\n' |
| 580 | )" | 584 | )" |
| 581 | local keyword_args_count="$(echo $keyword_args | awk -F, '{print NF}')" | 585 | local keyword_args_count="$(echo $keyword_args | awk -F, '{print NF}')" |
| 582 | 586 | ||
| 583 | # Set spec values from keyword arguments, if any. The remaining arguments | 587 | # Set spec values from keyword arguments, if any. The remaining arguments |
| 584 | # are all assumed to be keyword arguments. | 588 | # are all assumed to be keyword arguments. |
| 585 | while [[ $1 == --* ]]; do | 589 | while [[ $1 == --* ]]; do |
| 586 | # Remove the `--` at the start. | 590 | # Remove the `--` at the start. |
| 587 | local arg="${1#--}" | 591 | local arg="${1#--}" |
| 588 | 592 | ||
| 589 | # Get the argument name and value. | 593 | # Get the argument name and value. |
| 590 | if [[ $arg != *=* ]]; then | 594 | if [[ $arg != *=* ]]; then |
| 591 | local name="$arg" | 595 | local name="$arg" |
| 592 | local value='' | 596 | local value='' |
| 593 | else | 597 | else |
| 594 | local name="${arg%\=*}" | 598 | local name="${arg%\=*}" |
| 595 | local value="${arg#*=}" | 599 | local value="${arg#*=}" |
| 596 | fi | 600 | fi |
| 597 | 601 | ||
| 598 | if echo "$code" | grep -qm1 "^local $name="; then | 602 | if echo "$code" | grep -qm1 "^local $name="; then |
| 599 | echo "Argument '$name' repeated with the value '$value'". >&2 | 603 | echo "Argument '$name' repeated with the value '$value'". >&2 |
| 600 | return | 604 | return |
| 601 | fi | 605 | fi |
| 602 | 606 | ||
| 603 | # The specification for this argument, used for validations. | 607 | # The specification for this argument, used for validations. |
| 604 | local arg_line="$(echo "$keyword_args" | grep -m1 "^$name:\??\?")" | 608 | local arg_line="$(echo "$keyword_args" | grep -m1 "^$name:\??\?")" |
| 605 | 609 | ||
| 606 | # Validate argument and value. | 610 | # Validate argument and value. |
| 607 | if [[ -z $arg_line ]]; then | 611 | if [[ -z $arg_line ]]; then |
| 608 | # This argument is not known to us. | 612 | # This argument is not known to us. |
| 609 | echo "Unknown argument '$name'." >&2 | 613 | echo "Unknown argument '$name'." >&2 |
| 610 | return | 614 | return |
| 611 | 615 | ||
| 612 | elif (echo "$arg_line" | grep -qm1 ':') && [[ -z $value ]]; then | 616 | elif (echo "$arg_line" | grep -qm1 ':') && [[ -z $value ]]; then |
| 613 | # This argument needs a value, but is not provided. | 617 | # This argument needs a value, but is not provided. |
| 614 | echo "Required argument for '$name' not provided." >&2 | 618 | echo "Required argument for '$name' not provided." >&2 |
| 615 | return | 619 | return |
| 616 | 620 | ||
| 617 | elif (echo "$arg_line" | grep -vqm1 ':') && [[ ! -z $value ]]; then | 621 | elif (echo "$arg_line" | grep -vqm1 ':') && [[ ! -z $value ]]; then |
| 618 | # This argument doesn't need a value, but is provided. | 622 | # This argument doesn't need a value, but is provided. |
| 619 | echo "No argument required for '$name', but provided '$value'." >&2 | 623 | echo "No argument required for '$name', but provided '$value'." >&2 |
| 620 | return | 624 | return |
| 621 | 625 | ||
| 622 | fi | 626 | fi |
| 623 | 627 | ||
| 624 | if [[ -z $value ]]; then | 628 | if [[ -z $value ]]; then |
| 625 | value=true | 629 | value=true |
| 626 | fi | 630 | fi |
| 627 | 631 | ||
| 628 | --add-var "${name//-/_}" "$value" | 632 | --add-var "${name//-/_}" "$value" |
| 629 | shift | 633 | shift |
| 630 | done | 634 | done |
| 631 | 635 | ||
| 632 | echo "$code" | 636 | echo "$code" |
| 633 | 637 | ||
| 634 | unfunction -- --add-var | 638 | unfunction -- --add-var |
| 635 | 639 | ||
| 636 | } | 640 | } |
| 637 | 641 | ||
| 638 | # Echo the bundle specs as in the record. The first line is not echoed since it | 642 | # Echo the bundle specs as in the record. The first line is not echoed since it |
| 639 | # is a blank line. | 643 | # is a blank line. |
| 640 | -antigen-echo-record () { | 644 | -antigen-echo-record () { |
| 641 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' | 645 | echo "$_ANTIGEN_BUNDLE_RECORD" | sed -n '1!p' |
| 642 | } | 646 | } |
| 643 | 647 | ||
| 644 | -antigen-env-setup () { | 648 | -antigen-env-setup () { |
| 645 | 649 | ||
| 646 | # Helper function: Same as `export $1=$2`, but will only happen if the name | 650 | # Helper function: Same as `export $1=$2`, but will only happen if the name |
| 647 | # specified by `$1` is not already set. | 651 | # specified by `$1` is not already set. |
| 648 | -set-default () { | 652 | -set-default () { |
| 649 | local arg_name="$1" | 653 | local arg_name="$1" |
| 650 | local arg_value="$2" | 654 | local arg_value="$2" |
| 651 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" | 655 | eval "test -z \"\$$arg_name\" && export $arg_name='$arg_value'" |
| 652 | } | 656 | } |
| 653 | 657 | ||
| 654 | # Pre-startup initializations. | 658 | # Pre-startup initializations. |
| 655 | -set-default ANTIGEN_DEFAULT_REPO_URL \ | 659 | -set-default ANTIGEN_DEFAULT_REPO_URL \ |
| 656 | https://github.com/robbyrussell/oh-my-zsh.git | 660 | https://github.com/robbyrussell/oh-my-zsh.git |
| 657 | -set-default ADOTDIR $HOME/.antigen | 661 | -set-default ADOTDIR $HOME/.antigen |
| 658 | 662 | ||
| 659 | # Load the compinit module. Required for `compdef` to be defined, which is | 663 | # Load the compinit module. Required for `compdef` to be defined, which is |
| 660 | # used by many plugins to define completions. | 664 | # used by many plugins to define completions. |
| 661 | autoload -U compinit | 665 | autoload -U compinit |
| 662 | compinit -i | 666 | compinit -i |
| 663 | 667 | ||
| 664 | # Setup antigen's own completion. | 668 | # Setup antigen's own completion. |
| 665 | compdef _antigen antigen | 669 | compdef _antigen antigen |
| 666 | 670 | ||
| 667 | # Remove private functions. | 671 | # Remove private functions. |
| 668 | unfunction -- -set-default | 672 | unfunction -- -set-default |
| 669 | } | 673 | } |
| 670 | 674 | ||
| 671 | # Setup antigen's autocompletion | 675 | # Setup antigen's autocompletion |
| 672 | _antigen () { | 676 | _antigen () { |
| 673 | compadd \ | 677 | compadd \ |
| 674 | bundle \ | 678 | bundle \ |
| 675 | bundles \ | 679 | bundles \ |
| 676 | update \ | 680 | update \ |
| 677 | revert \ | 681 | revert \ |
| 678 | list \ | 682 | list \ |
| 679 | cleanup \ | 683 | cleanup \ |
| 680 | lib \ | 684 | lib \ |
| 681 | selfupdate \ | 685 | selfupdate \ |