1###################################################################### 2# This file was autogenerated by `make`. Do not edit it directly! 3###################################################################### 4# Antigen: A simple plugin manager for zsh 5 # Authors: Shrikant Sharat Kandula 6 # and Contributors <https://github.com/zsh-users/antigen/contributors> 7 # Homepage: http://antigen.sharats.me 8 # License: MIT License <mitl.sharats.me> 9zmodload zsh/parameter 10autoload -U is-at-least 11 12# While boot.zsh is part of the ext/cache functionallity it may be disabled 13# with ANTIGEN_CACHE flag, and it's always compiled with antigen.zsh 14if [[ $ANTIGEN_CACHE != false ]]; then 15 ANTIGEN_CACHE="${ANTIGEN_CACHE:-${ADOTDIR:-$HOME/.antigen}/init.zsh}" 16 ANTIGEN_RSRC="${ANTIGEN_RSRC:-${ADOTDIR:-$HOME/.antigen}/.resources}" 17 18 # It may not be necessary to check ANTIGEN_AUTO_CONFIG. 19 if [[ $ANTIGEN_AUTO_CONFIG != false && -f $ANTIGEN_RSRC ]]; then 20 # Check the list of files for configuration changes (uses -nt comp) 21 ANTIGEN_CHECK_FILES=$(cat $ANTIGEN_RSRC 2> /dev/null) 22 ANTIGEN_CHECK_FILES=(${(@f)ANTIGEN_CHECK_FILES}) 23 24 for config in $ANTIGEN_CHECK_FILES; do 25 if [[ "$config" -nt "$config.zwc" ]]; then 26 # Flag configuration file as newer 27 { zcompile "$config" } &! 28 # Kill cache file in order to force full loading (see a few lines below) 29 [[ -f "$ANTIGEN_CACHE" ]] && rm -f "$ANTIGEN_CACHE" 30 fi 31 done 32 fi 33 34 # If there is a cache file do load from it 35 if [[ -f $ANTIGEN_CACHE && ! $_ANTIGEN_CACHE_LOADED == true ]]; then 36 # Wrap antigen in order to defer cache source until `antigen-apply` 37 antigen() { 38 if [[ $1 == "apply" ]]; then 39 source "$ANTIGEN_CACHE" 40 # Handle `antigen-init` command properly 41 elif [[ $1 == "init" ]]; then 42 source "$2" 43 fi 44 } 45 # Do not continue loading antigen as cache bundle takes care of it. 46 return 0 47 fi 48fi 49[[ -z "$_ANTIGEN_INSTALL_DIR" ]] && _ANTIGEN_INSTALL_DIR=${0:A:h} 50 51# Each line in this string has the following entries separated by a space 52# character. 53# <repo-url>, <plugin-location>, <bundle-type>, <has-local-clone> 54[[ $_ANTIGEN_CACHE_LOADED != true ]] && typeset -aU _ANTIGEN_BUNDLE_RECORD 55 56# Do not load anything if git is not available. 57if (( ! $+commands[git] )); then 58 echo 'Antigen: Please install git to use Antigen.' >&2 59 return 1 60fi 61 62# Used to defer compinit/compdef 63typeset -a __deferred_compdefs 64compdef () { __deferred_compdefs=($__deferred_compdefs "$*") } 65 66# A syntax sugar to avoid the `-` when calling antigen commands. With this 67# function, you can write `antigen-bundle` as `antigen bundle` and so on. 68antigen () { 69 local cmd="$1" 70 if [[ -z "$cmd" ]]; then 71 echo 'Antigen: Please give a command to run.' >&2 72 return 1 73 fi 74 shift 75 76 if (( $+functions[antigen-$cmd] )); then 77 "antigen-$cmd" "$@" 78 return $? 79 else 80 echo "Antigen: Unknown command: $cmd" >&2 81 return 1 82 fi 83} 84# Returns the bundle's git revision 85# 86# Usage 87# -antigen-bundle-rev bundle-name [is_local_clone] 88# 89# Returns 90# Bundle rev-parse output (branch name or short ref name) 91-antigen-bundle-rev () { 92 local bundle=$1 93 local is_local_clone=$2 94 95 local bundle_path=$bundle 96 # Get bunde path inside $ADOTDIR if bundle was effectively cloned 97 if [[ "$is_local_clone" == "true" ]]; then 98 bundle_path=$(-antigen-get-clone-dir $bundle) 99 fi 100 101 local ref 102 ref=$(git --git-dir="$bundle_path/.git" rev-parse --abbrev-ref '@' 2>/dev/null) 103 104 # Avoid 'HEAD' when in detached mode 105 if [[ $ref == "HEAD" ]]; then 106 ref=$(git --git-dir="$bundle_path/.git" describe --tags --exact-match 2>/dev/null \ 107 || git --git-dir="$bundle_path/.git" rev-parse --short '@' 2>/dev/null || "-") 108 fi 109 echo $ref 110} 111# Usage: 112# -antigen-bundle-short-name "https://github.com/user/repo.git[|*]" "[branch/name]" 113# Returns: 114# user/repo@branch/name 115-antigen-bundle-short-name () { 116 local bundle_name="${1%|*}" 117 local bundle_branch="$2" 118 local match mbegin mend MATCH MBEGIN MEND 119 120 [[ "$bundle_name" =~ '.*/(.*/.*).*$' ]] && bundle_name=$match[1] 121 bundle_name="${bundle_name%.git*}" 122 123 if [[ -n $bundle_branch ]]; then 124 bundle_name="$bundle_name@$bundle_branch" 125 fi 126 127 echo $bundle_name 128} 129# Echo the bundle specs as in the record. The first line is not echoed since it 130# is a blank line. 131-antigen-echo-record () { 132 echo ${(j:\n:)_ANTIGEN_BUNDLE_RECORD} 133} 134# Filters _ANTIGEN_BUNDLE_RECORD for $1 135# 136# Usage 137# -antigen-find-bundle example/bundle 138# 139# Returns 140# String if bundle is found 141-antigen-find-bundle () { 142 echo $(-antigen-find-record $1 | cut -d' ' -f1) 143} 144 145# Filters _ANTIGEN_BUNDLE_RECORD for $1 146# 147# Usage 148# -antigen-find-record example/bundle 149# 150# Returns 151# String if record is found 152-antigen-find-record () { 153 local bundle=$1 154 155 if [[ $# -eq 0 ]]; then 156 return 1 157 fi 158 159 local record=${bundle/\|/\\\|} 160 echo "${_ANTIGEN_BUNDLE_RECORD[(r)*$record*]}" 161} 162# Returns bundle names from _ANTIGEN_BUNDLE_RECORD 163# 164# Usage 165# -antigen-get-bundles [--short|--simple|--long] 166# 167# Returns 168# List of bundles installed 169-antigen-get-bundles () { 170 local mode revision url bundle_name bundle_entry loc no_local_clone 171 local record bundle make_local_clone 172 mode=${1:-"--short"} 173 174 for record in $_ANTIGEN_BUNDLE_RECORD; do 175 bundle=(${(@s/ /)record}) 176 url=$bundle[1] 177 loc=$bundle[2] 178 make_local_clone=$bundle[4] 179 180 bundle_name=$(-antigen-bundle-short-name $url) 181 182 case "$mode" in 183 --short) 184 # Only check revision for bundle with a requested branch 185 if [[ $url == *\|* ]]; then 186 revision=$(-antigen-bundle-rev $url $make_local_clone) 187 else 188 revision="master" 189 fi 190 191 if [[ $loc != '/' ]]; then 192 bundle_name="$bundle_name ~ $loc" 193 fi 194 echo "$bundle_name @ $revision" 195 ;; 196 --simple) 197 echo "$bundle_name" 198 ;; 199 --long) 200 echo "$record" 201 ;; 202 esac 203 done 204} 205# Usage: 206# -antigen-get-clone-dir "https://github.com/zsh-users/zsh-syntax-highlighting.git[|feature/branch]" 207# Returns: 208# $ANTIGEN_BUNDLES/zsh-users/zsh-syntax-highlighting[-feature-branch] 209-antigen-get-clone-dir () { 210 local bundle="$1" 211 local url="${bundle%|*}" 212 local branch match mbegin mend MATCH MBEGIN MEND 213 [[ "$bundle" =~ "\|" ]] && branch="${bundle#*|}" 214 215 # Takes a repo url and mangles it, giving the path that this url will be 216 # cloned to. Doesn't actually clone anything. 217 local clone_dir="$ANTIGEN_BUNDLES" 218 219 url=$(-antigen-bundle-short-name $url) 220 221 # Suffix with branch/tag name 222 [[ -n "$branch" ]] && url="$url-${branch//\//-}" 223 url=${url//\*/x} 224 225 echo "$clone_dir/$url" 226} 227# Returns bundles flagged as make_local_clone 228# 229# Usage 230# -antigen-cloned-bundles 231# 232# Returns 233# Bundle metadata 234-antigen-get-cloned-bundles() { 235 -antigen-echo-record | 236 awk '$4 == "true" {print $1}' | 237 sort -u 238} 239# Returns a list of themes from a default library (omz) 240# 241# Usage 242# -antigen-get-themes 243# 244# Returns 245# List of themes by name 246-antigen-get-themes () { 247 local library='robbyrussell/oh-my-zsh' 248 local bundle=$(-antigen-find-bundle $library) 249 250 if [[ -n "$bundle" ]]; then 251 local dir=$(-antigen-get-clone-dir $ANTIGEN_DEFAULT_REPO_URL) 252 echo $(ls $dir/themes/ | eval "$_ANTIGEN_GREP_COMMAND '.zsh-theme$'" | sed 's/.zsh-theme//') 253 fi 254 255 return 0 256} 257 258# This function check ZSH_EVAL_CONTEXT to determine if running in interactive shell. 259# 260# Usage 261# -antigen-interactive-mode 262# 263# Returns 264# Either true or false depending if we are running in interactive mode 265-antigen-interactive-mode () { 266 WARN "-antigen-interactive-mode: $ZSH_EVAL_CONTEXT \$_ANTIGEN_INTERACTIVE = $_ANTIGEN_INTERACTIVE" 267 if [[ $_ANTIGEN_INTERACTIVE != "" ]]; then 268 [[ $_ANTIGEN_INTERACTIVE == true ]]; 269 return 270 fi 271 272 [[ "$ZSH_EVAL_CONTEXT" == toplevel* || "$ZSH_EVAL_CONTEXT" == cmdarg* ]]; 273} 274# Parses and retrieves a remote branch given a branch name. 275# 276# If the branch name contains '*' it will retrieve remote branches 277# and try to match against tags and heads, returning the latest matching. 278# 279# Usage 280# -antigen-parse-branch https://github.com/user/repo.git x.y.z 281# 282# Returns 283# Branch name 284-antigen-parse-branch () { 285 local url="$1" branch="$2" branches 286 287 local match mbegin mend MATCH MBEGIN MEND 288 289 if [[ "$branch" =~ '\*' ]]; then 290 branches=$(git ls-remote --tags -q "$url" "$branch"|cut -d'/' -f3|sort -n|tail -1) 291 # There is no --refs flag in git 1.8 and below, this way we 292 # emulate this flag -- also git 1.8 ref order is undefined. 293 branch=${${branches#*/*/}%^*} # Why you are like this? 294 fi 295 296 echo $branch 297} 298-antigen-update-repos () { 299 local repo bundle url target 300 local log=/tmp/antigen-v2-migrate.log 301 302 echo "It seems you have bundles cloned with Antigen v1.x." 303 echo "We'll try to convert directory structure to v2." 304 echo 305 306 echo -n "Moving bundles to '\$ADOTDIR/bundles'... " 307 308 # Migrate old repos -> bundles 309 local errors=0 310 for repo in $ADOTDIR/repos/*; do 311 bundle=${repo/$ADOTDIR\/repos\//} 312 bundle=${bundle//-SLASH-/\/} 313 bundle=${bundle//-COLON-/\:} 314 bundle=${bundle//-STAR-/\*} 315 url=${bundle//-PIPE-/\|} 316 target=$(-antigen-get-clone-dir $url) 317 mkdir -p "${target:A:h}" 318 echo " ---> ${repo/$ADOTDIR\/} -> ${target/$ADOTDIR\/}" | tee > $log 319 mv "$repo" "$target" &> $log 320 if [[ $? != 0 ]]; then 321 echo "Failed to migrate '$repo'!." 322 errors+=1 323 fi 324 done 325 326 if [[ $errors == 0 ]]; then 327 echo "Done." 328 else 329 echo "An error ocurred!" 330 fi 331 echo 332 333 if [[ "$(ls -A $ADOTDIR/repos | wc -l | xargs)" == 0 ]]; then 334 echo "You can safely remove \$ADOTDIR/repos." 335 else 336 echo "Some bundles couldn't be migrated. See \$ADOTDIR/repos." 337 fi 338 339 echo 340 if [[ $errors == 0 ]]; then 341 echo "Bundles migrated successfuly." 342 rm $log 343 else 344 echo "Some errors occured. Review migration log in '$log'." 345 fi 346 antigen-reset 347} 348# Ensure that a clone exists for the given repo url and branch. If the first 349# argument is `update` and if a clone already exists for the given repo 350# and branch, it is pull-ed, i.e., updated. 351# 352# This function expects three arguments in order: 353# - 'url=<url>' 354# - 'update=true|false' 355# - 'verbose=true|false' 356# 357# Returns true|false Whether cloning/pulling was succesful 358-antigen-ensure-repo () { 359 # Argument defaults. Previously using ${1:?"missing url argument"} format 360 # but it seems to mess up with cram 361 if (( $# < 1 )); then 362 echo "Antigen: Missing url argument." 363 return 1 364 fi 365 366 # The url. No sane default for this, so just empty. 367 local url=$1 368 # Check if we have to update. 369 local update=${2:-false} 370 # Verbose output. 371 local verbose=${3:-false} 372 373 shift $# 374 375 # Get the clone's directory as per the given repo url and branch. 376 local clone_dir=$(-antigen-get-clone-dir $url) 377 if [[ -d "$clone_dir" && $update == false ]]; then 378 return true 379 fi 380 381 # A temporary function wrapping the `git` command with repeated arguments. 382 --plugin-git () { 383 (\cd -q "$clone_dir" && eval ${ANTIGEN_CLONE_ENV} git --git-dir="$clone_dir/.git" --no-pager "$@" &>>! $ANTIGEN_LOG) 384 } 385 386 local success=false 387 388 # If its a specific branch that we want, checkout that branch. 389 local branch="master" # TODO FIX THIS 390 if [[ $url == *\|* ]]; then 391 branch="$(-antigen-parse-branch ${url%|*} ${url#*|})" 392 fi 393 394 if [[ ! -d $clone_dir ]]; then 395 eval ${ANTIGEN_CLONE_ENV} git clone ${=ANTIGEN_CLONE_OPTS} --branch "$branch" -- "${url%|*}" "$clone_dir" &>> $ANTIGEN_LOG 396 success=$? 397 elif $update; then 398 # Save current revision. 399 local old_rev="$(--plugin-git rev-parse HEAD)" 400 # Pull changes if update requested. 401 --plugin-git checkout "$branch" 402 --plugin-git pull origin "$branch" 403 success=$? 404 405 # Update submodules. 406 --plugin-git submodule update ${=ANTIGEN_SUBMODULE_OPTS} 407 # Get the new revision. 408 local new_rev="$(--plugin-git rev-parse HEAD)" 409 fi 410 411 if [[ -n $old_rev && $old_rev != $new_rev ]]; then 412 echo Updated from $old_rev[0,7] to $new_rev[0,7]. 413 if $verbose; then 414 --plugin-git log --oneline --reverse --no-merges --stat '@{1}..' 415 fi 416 fi 417 418 # Remove the temporary git wrapper function. 419 unfunction -- --plugin-git 420 421 return $success 422} 423# Helper function: Same as `$1=$2`, but will only happen if the name 424# specified by `$1` is not already set. 425-antigen-set-default () { 426 local arg_name="$1" 427 local arg_value="$2" 428 eval "test -z \"\$$arg_name\" && typeset -g $arg_name='$arg_value'" 429} 430 431-antigen-env-setup () { 432 typeset -gU fpath path 433 434 # Pre-startup initializations. 435 -antigen-set-default ANTIGEN_OMZ_REPO_URL \ 436 https://github.com/robbyrussell/oh-my-zsh.git 437 -antigen-set-default ANTIGEN_PREZTO_REPO_URL \ 438 https://github.com/sorin-ionescu/prezto.git 439 -antigen-set-default ANTIGEN_DEFAULT_REPO_URL $ANTIGEN_OMZ_REPO_URL 440 441 # Default Antigen directory. 442 -antigen-set-default ADOTDIR $HOME/.antigen 443 [[ ! -d $ADOTDIR ]] && mkdir -p $ADOTDIR 444 445 # Defaults bundles directory. 446 -antigen-set-default ANTIGEN_BUNDLES $ADOTDIR/bundles 447 448 # If there is no bundles directory, create it. 449 if [[ ! -d $ANTIGEN_BUNDLES ]]; then 450 mkdir -p $ANTIGEN_BUNDLES 451 # Check for v1 repos directory, transform it to v2 format. 452 [[ -d $ADOTDIR/repos ]] && -antigen-update-repos 453 fi 454 455 -antigen-set-default ANTIGEN_COMPDUMP "${ADOTDIR:-$HOME}/.zcompdump" 456 -antigen-set-default ANTIGEN_COMPINIT_OPTS "-i" 457 -antigen-set-default ANTIGEN_LOG /dev/null 458 459 # CLONE_OPTS uses ${=CLONE_OPTS} expansion so don't use spaces 460 # for arguments that can be passed as `--key=value`. 461 -antigen-set-default ANTIGEN_CLONE_ENV "GIT_TERMINAL_PROMPT=0" 462 -antigen-set-default ANTIGEN_CLONE_OPTS "--single-branch --recursive --depth=1" 463 -antigen-set-default ANTIGEN_SUBMODULE_OPTS "--recursive --depth=1" 464 465 # Complain when a bundle is already installed. 466 -antigen-set-default _ANTIGEN_WARN_DUPLICATES true 467 468 # Compatibility with oh-my-zsh themes. 469 -antigen-set-default _ANTIGEN_THEME_COMPAT true 470 471 -antigen-set-default _ANTIGEN_GREP_COMMAND 'GREP_OPTIONS= command grep ' 472 473 # Add default built-in extensions to load at start up 474 -antigen-set-default _ANTIGEN_BUILTIN_EXTENSIONS 'lock parallel defer cache' 475 476 # Setup antigen's own completion. 477 if -antigen-interactive-mode; then 478 TRACE "Gonna create compdump file @ env-setup" COMPDUMP 479 autoload -Uz compinit 480 compinit $ANTIGEN_COMPINIT_OPTS -d "$ANTIGEN_COMPDUMP" 481 compdef _antigen antigen 482 else 483 (( $+functions[antigen-ext-init] )) && antigen-ext-init 484 fi 485} 486# Load a given bundle by sourcing it. 487# 488# The function also modifies fpath to add the bundle path. 489# 490# Usage 491# -antigen-load "bundle-url" ["location"] ["make_local_clone"] ["btype"] 492# 493# Returns 494# Integer. 0 if success 1 if an error ocurred. 495-antigen-load () { 496 local bundle list 497 typeset -A bundle; bundle=($@) 498 499 typeset -Ua list; list=() 500 local location="${bundle[dir]}/${bundle[loc]}" 501 502 # Prioritize location when given. 503 if [[ -f "${location}" ]]; then 504 list=(${location}) 505 else 506 # Directory locations must be suffixed with slash 507 location="$location/" 508 509 # Prioritize theme with antigen-theme 510 if [[ ${bundle[btype]} == "theme" ]]; then 511 list=(${location}*.zsh-theme(N[1])) 512 fi 513 514 # Common frameworks 515 if [[ $#list == 0 ]]; then 516 # dot-plugin, init and functions support (omz, prezto) 517 # Support prezto function loading. See https://github.com/zsh-users/antigen/pull/428 518 list=(${location}*.plugin.zsh(N[1]) ${location}init.zsh(N[1]) ${location}/functions(N[1])) 519 fi 520 521 # Default to zsh and sh 522 if [[ $#list == 0 ]]; then 523 list=(${location}*.zsh(N) ${location}*.sh(N)) 524 fi 525 fi 526 527 -antigen-load-env ${(kv)bundle} 528 529 # If there is any sourceable try to load it 530 if ! -antigen-load-source "${list[@]}" && [[ ! -d ${location} ]]; then 531 return 1 532 fi 533 534 return 0 535} 536 537-antigen-load-env () { 538 typeset -A bundle; bundle=($@) 539 local location=${bundle[dir]}/${bundle[loc]} 540 541 # Load to path if there is no sourceable 542 if [[ -d ${location} ]]; then 543 PATH="$PATH:${location:A}" 544 fpath+=("${location:A}") 545 return 546 fi 547 548 PATH="$PATH:${location:A:h}" 549 fpath+=("${location:A:h}") 550} 551 552-antigen-load-source () { 553 typeset -a list 554 list=($@) 555 local src match mbegin mend MATCH MBEGIN MEND 556 557 # Return error when we're given an empty list 558 if [[ $#list == 0 ]]; then 559 return 1 560 fi 561 562 # Using a for rather than `source $list` as we need to check for zsh-themes 563 # In order to create antigen-compat file. This is only needed for interactive-mode 564 # theme switching, for static loading (cache) there is no need. 565 for src in $list; do 566 if [[ $_ANTIGEN_THEME_COMPAT == true && -f "$src" && "$src" == *.zsh-theme* ]]; then 567 local compat="${src:A}.antigen-compat" 568 echo "# Generated by Antigen. Do not edit!" >! "$compat" 569 cat $src | sed -Ee '/\{$/,/^\}/!{ 570 s/^local // 571 }' >>! "$compat" 572 src="$compat" 573 fi 574 575 if ! source "$src" 2>/dev/null; then 576 return 1 577 fi 578 done 579} 580# Usage: 581# -antigen-parse-args output_assoc_arr <args...> 582-antigen-parse-args () { 583 local argkey key value index=0 args 584 local match mbegin mend MATCH MBEGIN MEND 585 586 local var=$1 587 shift 588 589 # Bundle spec arguments' default values. 590 #setopt XTRACE VERBOSE 591 builtin typeset -A args 592 args[url]="$ANTIGEN_DEFAULT_REPO_URL" 593 #unsetopt XTRACE VERBOSE 594 args[loc]=/ 595 args[make_local_clone]=true 596 args[btype]=plugin 597 #args[branch]= # commented out as it may cause assoc array kv mismatch 598 599 while [[ $# -gt 0 ]]; do 600 argkey="${1%\=*}" 601 key="${argkey//--/}" 602 value="${1#*=}" 603 604 case "$argkey" in 605 --url|--loc|--branch|--btype) 606 if [[ "$value" == "$argkey" ]]; then 607 printf "Required argument for '%s' not provided.\n" $key >&2 608 else 609 args[$key]="$value" 610 fi 611 ;; 612 --no-local-clone) 613 args[make_local_clone]=false 614 ;; 615 --*) 616 printf "Unknown argument '%s'.\n" $key >&2 617 ;; 618 *) 619 value=$key 620 case $index in 621 0) 622 key=url 623 local domain="" 624 local url_path=$value 625 # Full url with protocol or ssh github url (github.com:org/repo) 626 if [[ "$value" =~ "://" || "$value" =~ ":" ]]; then 627 if [[ "$value" =~ [@.][^/:]+[:]?[0-9]*[:/]?(.*)@?$ ]]; then 628 url_path=$match[1] 629 domain=${value/$url_path/} 630 fi 631 fi 632 633 if [[ "$url_path" =~ '@' ]]; then 634 args[branch]="${url_path#*@}" 635 value="$domain${url_path%@*}" 636 else 637 value="$domain$url_path" 638 fi 639 ;; 640 1) key=loc ;; 641 esac 642 let index+=1 643 args[$key]="$value" 644 ;; 645 esac 646 647 shift 648 done 649 650 # Check if url is just the plugin name. Super short syntax. 651 if [[ "${args[url]}" != */* ]]; then 652 case "$ANTIGEN_DEFAULT_REPO_URL" in 653 "$ANTIGEN_OMZ_REPO_URL") 654 args[loc]="plugins/${args[url]}" 655 ;; 656 "$ANTIGEN_PREZTO_REPO_URL") 657 args[loc]="modules/${args[url]}" 658 ;; 659 *) 660 args[loc]="${args[url]}" 661 ;; 662 esac 663 args[url]="$ANTIGEN_DEFAULT_REPO_URL" 664 fi 665 666 # Resolve the url. 667 # Expand short github url syntax: `username/reponame`. 668 local url="${args[url]}" 669 if [[ $url != git://* && 670 $url != https://* && 671 $url != http://* && 672 $url != ssh://* && 673 $url != /* && 674 $url != *github.com:*/* 675 ]]; then 676 url="https://github.com/${url%.git}.git" 677 fi 678 args[url]="$url" 679 680 # Ignore local clone if url given is not a git directory 681 if [[ ${args[url]} == /* && ! -d ${args[url]}/.git ]]; then 682 args[make_local_clone]=false 683 fi 684 685 # Add the branch information to the url if we need to create a local clone. 686 # Format url in bundle-metadata format: url[|branch] 687 if [[ ! -z "${args[branch]}" && ${args[make_local_clone]} == true ]]; then 688 args[url]="${args[url]}|${args[branch]}" 689 fi 690 691 # Add the theme extension to `loc`, if this is a theme, but only 692 # if it's especified, ie, --loc=theme-name, in case when it's not 693 # specified antige-load-list will look for *.zsh-theme files 694 if [[ ${args[btype]} == "theme" && 695 ${args[loc]} != "/" && ${args[loc]} != *.zsh-theme ]]; then 696 args[loc]="${args[loc]}.zsh-theme" 697 fi 698 699 local name="${args[url]%|*}" 700 local branch="${args[branch]}" 701 702 # Extract bundle name. 703 if [[ "$name" =~ '.*/(.*/.*).*$' ]]; then 704 name="${match[1]}" 705 fi 706 name="${name%.git*}" 707 708 # Format bundle name with optional branch. 709 if [[ -n "${branch}" ]]; then 710 args[name]="${name}@${branch}" 711 else 712 args[name]="${name}" 713 fi 714 715 # Format bundle path. 716 if [[ ${args[make_local_clone]} == true ]]; then 717 local bpath="$name" 718 # Suffix with branch/tag name 719 if [[ -n "$branch" ]]; then 720 # bpath is in the form of repo/name@version => repo/name-version 721 # Replace / with - in bundle branch. 722 local bbranch=${branch//\//-} 723 # If branch/tag is semver-like do replace * by x. 724 bbranch=${bbranch//\*/x} 725 bpath="${name}-${bbranch}" 726 fi 727 728 bpath="$ANTIGEN_BUNDLES/$bpath" 729 args[dir]="${(qq)bpath}" 730 else 731 # if it's local then path is just the "url" argument, loc remains the same 732 args[dir]=${args[url]} 733 fi 734 735 # Escape url and branch (may contain semver-like and pipe characters) 736 args[url]="${(qq)args[url]}" 737 if [[ -n "${args[branch]}" ]]; then 738 args[branch]="${(qq)args[branch]}" 739 fi 740 741 # Escape bundle name (may contain semver-like characters) 742 args[name]="${(qq)args[name]}" 743 744 eval "${var}=(${(kv)args})" 745 746 return 0 747} 748# Updates revert-info data with git hash. 749# 750# This does process only cloned bundles. 751# 752# Usage 753# -antigen-revert-info 754# 755# Returns 756# Nothing. Generates/updates $ADOTDIR/revert-info. 757-antigen-revert-info() { 758 local url 759 # Update your bundles, i.e., `git pull` in all the plugin repos. 760 date >! $ADOTDIR/revert-info 761 762 -antigen-get-cloned-bundles | while read url; do 763 local clone_dir="$(-antigen-get-clone-dir "$url")" 764 if [[ -d "$clone_dir" ]]; then 765 (echo -n "$clone_dir:" 766 \cd -q "$clone_dir" 767 git rev-parse HEAD) >> $ADOTDIR/revert-info 768 fi 769 done 770} 771-antigen-use-oh-my-zsh () { 772 typeset -g ZSH ZSH_CACHE_DIR 773 ANTIGEN_DEFAULT_REPO_URL=$ANTIGEN_OMZ_REPO_URL 774 if [[ -z "$ZSH" ]]; then 775 ZSH="$(-antigen-get-clone-dir "$ANTIGEN_DEFAULT_REPO_URL")" 776 fi 777 if [[ -z "$ZSH_CACHE_DIR" ]]; then 778 ZSH_CACHE_DIR="$ZSH/cache/" 779 fi 780 antigen-bundle --loc=lib 781} 782-antigen-use-prezto () { 783 ANTIGEN_DEFAULT_REPO_URL=$ANTIGEN_PREZTO_REPO_URL 784 antigen-bundle "$ANTIGEN_PREZTO_REPO_URL" 785} 786# Initialize completion 787antigen-apply () { 788 LOG "Called antigen-apply" 789 790 # Load the compinit module. This will readefine the `compdef` function to 791 # the one that actually initializes completions. 792 TRACE "Gonna create compdump file @ apply" COMPDUMP 793 autoload -Uz compinit 794 compinit $ANTIGEN_COMPINIT_OPTS -d "$ANTIGEN_COMPDUMP" 795 796 # Apply all `compinit`s that have been deferred. 797 local cdef 798 for cdef in "${__deferred_compdefs[@]}"; do 799 compdef "$cdef" 800 done 801 802 { zcompile "$ANTIGEN_COMPDUMP" } &! 803 804 unset __deferred_compdefs 805} 806# Syntaxes 807# antigen-bundle <url> [<loc>=/] 808# Keyword only arguments: 809# branch - The branch of the repo to use for this bundle. 810antigen-bundle () { 811 TRACE "Called antigen-bundle with $@" BUNDLE 812 if [[ -z "$1" ]]; then 813 printf "Antigen: Must provide a bundle url or name.\n" >&2 814 return 1 815 fi 816 817 builtin typeset -A bundle; -antigen-parse-args 'bundle' ${=@} 818 if [[ -z ${bundle[btype]} ]]; then 819 bundle[btype]=bundle 820 fi 821 822 local record="${bundle[url]} ${bundle[loc]} ${bundle[btype]} ${bundle[make_local_clone]}" 823 if [[ $_ANTIGEN_WARN_DUPLICATES == true && ! ${_ANTIGEN_BUNDLE_RECORD[(I)$record]} == 0 ]]; then 824 printf "Seems %s is already installed!\n" ${bundle[name]} 825 return 1 826 fi 827 828 # Clone bundle if we haven't done do already. 829 if [[ ! -d "${bundle[dir]}" ]]; then 830 if ! -antigen-bundle-install ${(kv)bundle}; then 831 return 1 832 fi 833 fi 834 835 # Load the plugin. 836 if ! -antigen-load ${(kv)bundle}; then 837 TRACE "-antigen-load failed to load ${bundle[name]}" BUNDLE 838 printf "Antigen: Failed to load %s.\n" ${bundle[btype]} >&2 839 return 1 840 fi 841 842 # Only add it to the record if it could be installed and loaded. 843 _ANTIGEN_BUNDLE_RECORD+=("$record") 844} 845 846# 847# Usage: 848# -antigen-bundle-install <record> 849# Returns: 850# 1 if it fails to install bundle 851-antigen-bundle-install () { 852 typeset -A bundle; bundle=($@) 853 854 # Ensure a clone exists for this repo, if needed. 855 # Get the clone's directory as per the given repo url and branch. 856 local bpath="${bundle[dir]}" 857 # Clone if it doesn't already exist. 858 local start=$(date +'%s') 859 860 printf "Installing %s... " "${bundle[name]}" 861 862 if ! -antigen-ensure-repo "${bundle[url]}"; then 863 # Return immediately if there is an error cloning 864 TRACE "-antigen-bundle-instal failed to clone ${bundle[url]}" BUNDLE 865 printf "Error! Activate logging and try again.\n" >&2 866 return 1 867 fi 868 869 local took=$(( $(date +'%s') - $start )) 870 printf "Done. Took %ds.\n" $took 871} 872antigen-bundles () { 873 # Bulk add many bundles at one go. Empty lines and lines starting with a `#` 874 # are ignored. Everything else is given to `antigen-bundle` as is, no 875 # quoting rules applied. 876 local line 877 setopt localoptions no_extended_glob # See https://github.com/zsh-users/antigen/issues/456 878 eval "$_ANTIGEN_GREP_COMMAND '^[[:space:]]*[^[:space:]#]'" | while read line; do 879 antigen-bundle ${=line%#*} 880 done 881} 882# Cleanup unused repositories. 883antigen-cleanup () { 884 local force=false 885 if [[ $1 == --force ]]; then 886 force=true 887 fi 888 889 if [[ ! -d "$ANTIGEN_BUNDLES" || -z "$(\ls -A "$ANTIGEN_BUNDLES")" ]]; then 890 echo "You don't have any bundles." 891 return 0 892 fi 893 894 # Find directores in ANTIGEN_BUNDLES, that are not in the bundles record. 895 typeset -a unused_clones clones 896 897 local url record clone 898 for record in $(-antigen-get-cloned-bundles); do 899 url=${record% /*} 900 clones+=("$(-antigen-get-clone-dir $url)") 901 done 902 903 for clone in $ANTIGEN_BUNDLES/*/*(/); do 904 if [[ $clones[(I)$clone] == 0 ]]; then 905 unused_clones+=($clone) 906 fi 907 done 908 909 if [[ -z $unused_clones ]]; then 910 echo "You don't have any unidentified bundles." 911 return 0 912 fi 913 914 echo 'You have clones for the following repos, but are not used.' 915 echo "\n${(j:\n:)unused_clones}" 916 917 if $force || (echo -n '\nDelete them all? [y/N] '; read -q); then 918 echo 919 echo 920 for clone in $unused_clones; do 921 echo -n "Deleting clone \"$clone\"..." 922 \rm -rf "$clone" 923 924 echo ' done.' 925 done 926 else 927 echo 928 echo "Nothing deleted." 929 fi 930} 931antigen-help () { 932 antigen-version 933 934 cat <<EOF 935 936Antigen is a plugin management system for zsh. It makes it easy to grab awesome 937shell scripts and utilities, put up on Github. 938 939Usage: antigen <command> [args] 940 941Commands: 942 apply Must be called in the zshrc after all calls to 'antigen bundle'. 943 bundle Install and load a plugin. 944 cache-gen Generate Antigen's cache with currently loaded bundles. 945 cleanup Remove clones of repos not used by any loaded plugins. 946 init Use caching to quickly load bundles. 947 list List currently loaded plugins. 948 purge Remove a bundle from the filesystem. 949 reset Clean the generated cache. 950 restore Restore plugin state from a snapshot file. 951 revert Revert plugins to their state prior to the last time 'antigen 952 update' was run. 953 selfupdate Update antigen. 954 snapshot Create a snapshot of all active plugin repos and save it to a 955 snapshot file. 956 update Update plugins. 957 use Load a supported zsh pre-packaged framework. 958 959For further details and complete documentation, visit the project's page at 960'http://antigen.sharats.me'. 961EOF 962} 963# Antigen command to load antigen configuration 964# 965# This method is slighlty more performing than using various antigen-* methods. 966# 967# Usage 968# Referencing an antigen configuration file: 969# 970# antigen-init "/path/to/antigenrc" 971# 972# or using HEREDOCS: 973# 974# antigen-init <<EOBUNDLES 975# antigen use oh-my-zsh 976# 977# antigen bundle zsh/bundle 978# antigen bundle zsh/example 979# 980# antigen theme zsh/theme 981# 982# antigen apply 983# EOBUNDLES 984# 985# Returns 986# Nothing 987antigen-init () { 988 local src="$1" line 989 990 # If we're given an argument it should be a path to a file 991 if [[ -n "$src" ]]; then 992 if [[ -f "$src" ]]; then 993 source "$src" 994 return 995 else 996 printf "Antigen: invalid argument provided.\n" >&2 997 return 1 998 fi 999 fi 1000 1001 # Otherwise we expect it to be a heredoc 1002 eval "$_ANTIGEN_GREP_COMMAND '^[[:space:]]*[^[:space:]#]'" | while read -r line; do 1003 eval $line 1004 done 1005} 1006# List instaled bundles either in long (record), short or simple format. 1007# 1008# Usage 1009# antigen-list [--short|--long|--simple] 1010# 1011# Returns 1012# List of bundles 1013antigen-list () { 1014 local format=$1 1015 1016 # List all currently installed bundles. 1017 if [[ -z $_ANTIGEN_BUNDLE_RECORD ]]; then 1018 echo "You don't have any bundles." >&2 1019 return 1 1020 fi 1021 1022 -antigen-get-bundles $format 1023} 1024# Remove a bundle from filesystem 1025# 1026# Usage 1027# antigen-purge example/bundle [--force] 1028# 1029# Returns 1030# Nothing. Removes bundle from filesystem. 1031antigen-purge () { 1032 local bundle=$1 1033 local force=$2 1034 1035 if [[ $# -eq 0 ]]; then 1036 echo "Antigen: Missing argument." >&2 1037 return 1 1038 fi 1039 1040 if -antigen-purge-bundle $bundle $force; then 1041 antigen-reset 1042 else 1043 return $? 1044 fi 1045 1046 return 0 1047} 1048 1049# Remove a bundle from filesystem 1050# 1051# Usage 1052# antigen-purge example/bundle [--force] 1053# 1054# Returns 1055# Nothing. Removes bundle from filesystem. 1056-antigen-purge-bundle () { 1057 local bundle=$1 1058 local force=$2 1059 local clone_dir="" 1060 1061 local record="" 1062 local url="" 1063 local make_local_clone="" 1064 1065 if [[ $# -eq 0 ]]; then 1066 echo "Antigen: Missing argument." >&2 1067 return 1 1068 fi 1069 1070 # local keyword doesn't work on zsh <= 5.0.0 1071 record=$(-antigen-find-record $bundle) 1072 1073 if [[ ! -n "$record" ]]; then 1074 echo "Bundle not found in record. Try 'antigen bundle $bundle' first." >&2 1075 return 1 1076 fi 1077 1078 url="$(echo "$record" | cut -d' ' -f1)" 1079 make_local_clone=$(echo "$record" | cut -d' ' -f4) 1080 1081 if [[ $make_local_clone == "false" ]]; then 1082 echo "Bundle has no local clone. Will not be removed." >&2 1083 return 1 1084 fi 1085 1086 clone_dir=$(-antigen-get-clone-dir "$url") 1087 if [[ $force == "--force" ]] || read -q "?Remove '$clone_dir'? (y/n) "; then 1088 # Need empty line after read -q 1089 [[ ! -n $force ]] && echo "" || echo "Removing '$clone_dir'."; 1090 rm -rf "$clone_dir" 1091 return $? 1092 fi 1093 1094 return 1 1095} 1096# Removes cache payload and metadata if available 1097# 1098# Usage 1099# antigen-reset 1100# 1101# Returns 1102# Nothing 1103antigen-reset () { 1104 [[ -f "$ANTIGEN_CACHE" ]] && rm -f "$ANTIGEN_CACHE" "$ANTIGEN_CACHE.zwc" 1> /dev/null 1105 [[ -f "$ANTIGEN_RSRC" ]] && rm -f "$ANTIGEN_RSRC" 1> /dev/null 1106 [[ -f "$ANTIGEN_COMPDUMP" ]] && rm -f "$ANTIGEN_COMPDUMP" "$ANTIGEN_COMPDUMP.zwc" 1> /dev/null 1107 [[ -f "$ANTIGEN_LOCK" ]] && rm -f "$ANTIGEN_LOCK" 1> /dev/null 1108 echo 'Done. Please open a new shell to see the changes.' 1109} 1110antigen-restore () { 1111 local line 1112 if [[ $# == 0 ]]; then 1113 echo 'Please provide a snapshot file to restore from.' >&2 1114 return 1 1115 fi 1116 1117 local snapshot_file="$1" 1118 1119 # TODO: Before doing anything with the snapshot file, verify its checksum. 1120 # If it fails, notify this to the user and confirm if restore should 1121 # proceed. 1122 1123 echo -n "Restoring from $snapshot_file..." 1124 1125 sed -n '1!p' "$snapshot_file" | 1126 while read line; do 1127 local version_hash="${line%% *}" 1128 local url="${line##* }" 1129 local clone_dir="$(-antigen-get-clone-dir "$url")" 1130 1131 if [[ ! -d $clone_dir ]]; then 1132 git clone "$url" "$clone_dir" &> /dev/null 1133 fi 1134 1135 (\cd -q "$clone_dir" && git checkout $version_hash) &> /dev/null 1136 done 1137 1138 echo ' done.' 1139 echo 'Please open a new shell to get the restored changes.' 1140} 1141# Reads $ADORDIR/revert-info and restores bundles' revision 1142antigen-revert () { 1143 local line 1144 if [[ -f $ADOTDIR/revert-info ]]; then 1145 cat $ADOTDIR/revert-info | sed -n '1!p' | while read line; do 1146 local dir="$(echo "$line" | cut -d: -f1)" 1147 git --git-dir="$dir/.git" --work-tree="$dir" \ 1148 checkout "$(echo "$line" | cut -d: -f2)" 2> /dev/null 1149 done 1150 1151 echo "Reverted to state before running -update on $( 1152 cat $ADOTDIR/revert-info | sed -n '1p')." 1153 1154 else 1155 echo 'No revert information available. Cannot revert.' >&2 1156 return 1 1157 fi 1158} 1159# Update (with `git pull`) antigen itself. 1160# TODO: Once update is finished, show a summary of the new commits, as a kind of 1161# "what's new" message. 1162antigen-selfupdate () { 1163 (\cd -q $_ANTIGEN_INSTALL_DIR 1164 if [[ ! ( -d .git || -f .git ) ]]; then 1165 echo "Your copy of antigen doesn't appear to be a git clone. " \ 1166 "The 'selfupdate' command cannot work in this case." 1167 return 1 1168 fi 1169 local head="$(git rev-parse --abbrev-ref HEAD)" 1170 if [[ $head == "HEAD" ]]; then 1171 # If current head is detached HEAD, checkout to master branch. 1172 git checkout master 1173 fi 1174 git pull 1175 1176 # TODO Should be transparently hooked by zcache 1177 antigen-reset &>> /dev/null 1178 ) 1179} 1180antigen-snapshot () { 1181 local snapshot_file="${1:-antigen-shapshot}" 1182 local urls url dir version_hash snapshot_content 1183 local -a bundles 1184 1185 # The snapshot content lines are pairs of repo-url and git version hash, in 1186 # the form: 1187 # <version-hash> <repo-url> 1188 urls=$(-antigen-echo-record | awk '$4 == "true" {print $1}' | sort -u) 1189 for url in ${(f)urls}; do 1190 dir="$(-antigen-get-clone-dir "$url")" 1191 version_hash="$(\cd -q "$dir" && git rev-parse HEAD)" 1192 bundles+=("$version_hash $url"); 1193 done 1194 snapshot_content=${(j:\n:)bundles} 1195 1196 { 1197 # The first line in the snapshot file is for metadata, in the form: 1198 # key='value'; key='value'; key='value'; 1199 # Where `key`s are valid shell variable names. 1200 1201 # Snapshot version. Has no relation to antigen version. If the snapshot 1202 # file format changes, this number can be incremented. 1203 echo -n "version='1';" 1204 1205 # Snapshot creation date+time. 1206 echo -n " created_on='$(date)';" 1207 1208 # Add a checksum with the md5 checksum of all the snapshot lines. 1209 chksum() { (md5sum; test $? = 127 && md5) 2>/dev/null | cut -d' ' -f1 } 1210 local checksum="$(echo "$snapshot_content" | chksum)" 1211 unset -f chksum; 1212 echo -n " checksum='${checksum%% *}';" 1213 1214 # A newline after the metadata and then the snapshot lines. 1215 echo "\n$snapshot_content" 1216 1217 } > "$snapshot_file" 1218} 1219# Loads a given theme. 1220# 1221# Shares the same syntax as antigen-bundle command. 1222# 1223# Usage 1224# antigen-theme zsh/theme[.zsh-theme] 1225# 1226# Returns 1227# 0 if everything was succesfully 1228antigen-theme () { 1229 local name=$1 result=0 record 1230 local match mbegin mend MATCH MBEGIN MEND 1231 1232 if [[ -z "$1" ]]; then 1233 printf "Antigen: Must provide a theme url or name.\n" >&2 1234 return 1 1235 fi 1236 1237 -antigen-theme-reset-hooks 1238 1239 record=$(-antigen-find-record "theme") 1240 if [[ "$1" != */* && "$1" != --* ]]; then 1241 # The first argument is just a name of the plugin, to be picked up from 1242 # the default repo. 1243 antigen-bundle --loc=themes/$name --btype=theme 1244 1245 else 1246 antigen-bundle "$@" --btype=theme 1247 1248 fi 1249 result=$? 1250 1251 # Remove a theme from the record if the following conditions apply: 1252 # - there was no error in bundling the given theme 1253 # - there is a theme registered 1254 # - registered theme is not the same as the current one 1255 if [[ $result == 0 && -n $record ]]; then 1256 # http://zsh-workers.zsh.narkive.com/QwfCWpW8/what-s-wrong-with-this-expression 1257 if [[ "$record" =~ "$@" ]]; then 1258 return $result 1259 else 1260 _ANTIGEN_BUNDLE_RECORD[$_ANTIGEN_BUNDLE_RECORD[(I)$record]]=() 1261 fi 1262 fi 1263 1264 return $result 1265} 1266 1267-antigen-theme-reset-hooks () { 1268 # This is only needed on interactive mode 1269 autoload -U add-zsh-hook is-at-least 1270 local hook 1271 1272 # Clear out prompts 1273 PROMPT="" 1274 if [[ -n $RPROMPT ]]; then 1275 RPROMPT="" 1276 fi 1277 1278 for hook in chpwd precmd preexec periodic; do 1279 add-zsh-hook -D "${hook}" "prompt_*" 1280 # common in omz themes 1281 add-zsh-hook -D "${hook}" "*_${hook}" 1282 add-zsh-hook -d "${hook}" "vcs_info" 1283 done 1284} 1285# Updates the bundles or a single bundle. 1286# 1287# Usage 1288# antigen-update [example/bundle] 1289# 1290# Returns 1291# Nothing. Performs a `git pull`. 1292antigen-update () { 1293 local bundle=$1 url 1294 1295 # Clear log 1296 :> $ANTIGEN_LOG 1297 1298 # Update revert-info data 1299 -antigen-revert-info 1300 1301 # If no argument is given we update all bundles 1302 if [[ $# -eq 0 ]]; then 1303 # Here we're ignoring all non cloned bundles (ie, --no-local-clone) 1304 -antigen-get-cloned-bundles | while read url; do 1305 -antigen-update-bundle $url 1306 done 1307 # TODO next minor version 1308 # antigen-reset 1309 else 1310 if -antigen-update-bundle $bundle; then 1311 # TODO next minor version 1312 # antigen-reset 1313 else 1314 return $? 1315 fi 1316 fi 1317} 1318 1319# Updates a bundle performing a `git pull`. 1320# 1321# Usage 1322# -antigen-update-bundle example/bundle 1323# 1324# Returns 1325# Nothing. Performs a `git pull`. 1326-antigen-update-bundle () { 1327 local bundle="$1" 1328 local record="" 1329 local url="" 1330 local make_local_clone="" 1331 local start=$(date +'%s') 1332 1333 if [[ $# -eq 0 ]]; then 1334 printf "Antigen: Missing argument.\n" >&2 1335 return 1 1336 fi 1337 1338 record=$(-antigen-find-record $bundle) 1339 if [[ ! -n "$record" ]]; then 1340 printf "Bundle not found in record. Try 'antigen bundle %s' first.\n" $bundle >&2 1341 return 1 1342 fi 1343 1344 url="$(echo "$record" | cut -d' ' -f1)" 1345 make_local_clone=$(echo "$record" | cut -d' ' -f4) 1346 1347 local branch="master" 1348 if [[ $url == *\|* ]]; then 1349 branch="$(-antigen-parse-branch ${url%|*} ${url#*|})" 1350 fi 1351 1352 printf "Updating %s... " $(-antigen-bundle-short-name "$url" "$branch") 1353 1354 if [[ $make_local_clone == "false" ]]; then 1355 printf "Bundle has no local clone. Will not be updated.\n" >&2 1356 return 1 1357 fi 1358 1359 # update=true verbose=false 1360 if ! -antigen-ensure-repo "$url" true false; then 1361 printf "Error! Activate logging and try again.\n" >&2 1362 return 1 1363 fi 1364 1365 local took=$(( $(date +'%s') - $start )) 1366 printf "Done. Took %ds.\n" $took 1367} 1368antigen-use () { 1369 if [[ $1 == oh-my-zsh ]]; then 1370 -antigen-use-oh-my-zsh 1371 elif [[ $1 == prezto ]]; then 1372 -antigen-use-prezto 1373 elif [[ $1 != "" ]]; then 1374 ANTIGEN_DEFAULT_REPO_URL=$1 1375 antigen-bundle $@ 1376 else 1377 echo 'Usage: antigen-use <library-name|url>' >&2 1378 echo 'Where <library-name> is any one of the following:' >&2 1379 echo ' * oh-my-zsh' >&2 1380 echo ' * prezto' >&2 1381 echo '<url> is the full url.' >&2 1382 return 1 1383 fi 1384} 1385antigen-version () { 1386 local extensions 1387 1388 printf "Antigen %s (%s)\nRevision date: %s\n" "v2.2.3" "ff391b5" "2018-01-02 13:19:57 +0100" 1389 1390 # Show extension information if any is available 1391 if (( $+functions[antigen-ext] )); then 1392 typeset -a extensions; extensions=($(antigen-ext-list)) 1393 if [[ $#extensions -gt 0 ]]; then 1394 printf "Extensions loaded: %s\n" ${(j:, :)extensions} 1395 fi 1396 fi 1397} 1398typeset -Ag _ANTIGEN_HOOKS; _ANTIGEN_HOOKS=() 1399typeset -Ag _ANTIGEN_HOOKS_META; _ANTIGEN_HOOKS_META=() 1400typeset -g _ANTIGEN_HOOK_PREFIX="-antigen-hook-" 1401typeset -g _ANTIGEN_EXTENSIONS; _ANTIGEN_EXTENSIONS=() 1402 1403# -antigen-add-hook antigen-apply antigen-apply-hook replace 1404# - Replaces hooked function with hook, do not call hooked function 1405# - Return -1 to stop calling further hooks 1406# -antigen-add-hook antigen-apply antigen-apply-hook pre (pre-call) 1407# - By default it will call hooked function 1408# -antigen-add-hook antigen-pply antigen-apply-hook post (post-call) 1409# - Calls antigen-apply and then calls hook function 1410# Usage: 1411# -antigen-add-hook antigen-apply antigen-apply-hook ["replace"|"pre"|"post"] ["once"|"repeat"] 1412antigen-add-hook () { 1413 local target="$1" hook="$2" type="$3" mode="${4:-repeat}" 1414 1415 if (( ! $+functions[$target] )); then 1416 printf "Antigen: Function %s doesn't exist.\n" $target 1417 return 1 1418 fi 1419 1420 if (( ! $+functions[$hook] )); then 1421 printf "Antigen: Function %s doesn't exist.\n" $hook 1422 return 1 1423 fi 1424 1425 if [[ "${_ANTIGEN_HOOKS[$target]}" == "" ]]; then 1426 _ANTIGEN_HOOKS[$target]="${hook}" 1427 else 1428 _ANTIGEN_HOOKS[$target]="${_ANTIGEN_HOOKS[$target]}:${hook}" 1429 fi 1430 1431 _ANTIGEN_HOOKS_META[$hook]="target $target type $type mode $mode called 0" 1432 1433 # Do shadow for this function if there is none already 1434 local hook_function="${_ANTIGEN_HOOK_PREFIX}$target" 1435 if (( ! $+functions[$hook_function] )); then 1436 # Preserve hooked function 1437 eval "function ${_ANTIGEN_HOOK_PREFIX}$(functions -- $target)" 1438 1439 # Create hook, call hook-handler to further process hook functions 1440 eval "function $target () { 1441 noglob -antigen-hook-handler $target \$@ 1442 return \$? 1443 }" 1444 fi 1445 1446 return 0 1447} 1448 1449# Private function to handle multiple hooks in a central point. 1450-antigen-hook-handler () { 1451 local target="$1" args hook called 1452 local hooks meta 1453 shift 1454 typeset -a args; args=(${@}) 1455 1456 typeset -a pre_hooks replace_hooks post_hooks; 1457 typeset -a hooks; hooks=(${(s|:|)_ANTIGEN_HOOKS[$target]}) 1458 1459 typeset -A meta; 1460 for hook in $hooks; do 1461 meta=(${(s: :)_ANTIGEN_HOOKS_META[$hook]}) 1462 if [[ ${meta[mode]} == "once" && ${meta[called]} == 1 ]]; then 1463 WARN "Ignoring hook due to mode ${meta[mode]}: $hook" 1464 continue 1465 fi 1466 1467 let called=${meta[called]}+1 1468 meta[called]=$called 1469 _ANTIGEN_HOOKS_META[$hook]="${(kv)meta}" 1470 WARN "Updated meta: "${(kv)meta} 1471 1472 case "${meta[type]}" in 1473 "pre") 1474 pre_hooks+=($hook) 1475 ;; 1476 "replace") 1477 replace_hooks+=($hook) 1478 ;; 1479 "post") 1480 post_hooks+=($hook) 1481 ;; 1482 esac 1483 done 1484 1485 WARN "Processing hooks: ${hooks}" 1486 1487 for hook in $pre_hooks; do 1488 WARN "Pre hook:" $hook $args 1489 noglob $hook $args 1490 [[ $? == -1 ]] && WARN "$hook shortcircuited" && return $ret 1491 done 1492 1493 # A replace hook will return inmediately 1494 local replace_hook=0 ret=0 1495 for hook in $replace_hooks; do 1496 replace_hook=1 1497 # Should not be needed if `antigen-remove-hook` removed unneeded hooks. 1498 if (( $+functions[$hook] )); then 1499 WARN "Replace hook:" $hook $args 1500 noglob $hook $args 1501 [[ $? == -1 ]] && WARN "$hook shortcircuited" && return $ret 1502 fi 1503 done 1504 1505 if [[ $replace_hook == 0 ]]; then 1506 WARN "${_ANTIGEN_HOOK_PREFIX}$target $args" 1507 noglob ${_ANTIGEN_HOOK_PREFIX}$target $args 1508 ret=$? 1509 else 1510 WARN "Replaced hooked function." 1511 fi 1512 1513 for hook in $post_hooks; do 1514 WARN "Post hook:" $hook $args 1515 noglob $hook $args 1516 [[ $? == -1 ]] && WARN "$hook shortcircuited" && return $ret 1517 done 1518 1519 LOG "Return from hook ${target} with ${ret}" 1520 1521 return $ret 1522} 1523 1524# Usage: 1525# -antigen-remove-hook antigen-apply-hook 1526antigen-remove-hook () { 1527 local hook="$1" 1528 typeset -A meta; meta=(${(s: :)_ANTIGEN_HOOKS_META[$hook]}) 1529 local target="${meta[target]}" 1530 local -a hooks; hooks=(${(s|:|)_ANTIGEN_HOOKS[$target]}) 1531 1532 # Remove registered hook 1533 if [[ $#hooks > 0 ]]; then 1534 hooks[$hooks[(I)$hook]]=() 1535 fi 1536 _ANTIGEN_HOOKS[${target}]="${(j|:|)hooks}" 1537 1538 if [[ $#hooks == 0 ]]; then 1539 # Destroy base hook 1540 eval "function $(functions -- ${_ANTIGEN_HOOK_PREFIX}$target | sed s/${_ANTIGEN_HOOK_PREFIX}//)" 1541 if (( $+functions[${_ANTIGEN_HOOK_PREFIX}$target] )); then 1542 unfunction -- "${_ANTIGEN_HOOK_PREFIX}$target" 1543 fi 1544 fi 1545 1546 unfunction -- $hook 2> /dev/null 1547} 1548 1549# Remove all defined hooks. 1550-antigen-reset-hooks () { 1551 local target 1552 1553 for target in ${(k)_ANTIGEN_HOOKS}; do 1554 # Release all hooked functions 1555 eval "function $(functions -- ${_ANTIGEN_HOOK_PREFIX}$target | sed s/${_ANTIGEN_HOOK_PREFIX}//)" 1556 unfunction -- "${_ANTIGEN_HOOK_PREFIX}$target" 2> /dev/null 1557 done 1558 1559 _ANTIGEN_HOOKS=() 1560 _ANTIGEN_HOOKS_META=() 1561 _ANTIGEN_EXTENSIONS=() 1562} 1563 1564# Initializes an extension 1565# Usage: 1566# antigen-ext ext-name 1567antigen-ext () { 1568 local ext=$1 1569 local func="-antigen-$ext-init" 1570 if (( $+functions[$func] && $_ANTIGEN_EXTENSIONS[(I)$ext] == 0 )); then 1571 eval $func 1572 local ret=$? 1573 WARN "$func return code was $ret" 1574 if (( $ret == 0 )); then 1575 LOG "LOADED EXTENSION $ext" EXT 1576 -antigen-$ext-execute && _ANTIGEN_EXTENSIONS+=($ext) 1577 else 1578 WARN "IGNORING EXTENSION $func" EXT 1579 return 1 1580 fi 1581 1582 else 1583 printf "Antigen: No extension defined or already loaded: %s\n" $func >&2 1584 return 1 1585 fi 1586} 1587 1588# List installed extensions 1589# Usage: 1590# antigen ext-list 1591antigen-ext-list () { 1592 echo $_ANTIGEN_EXTENSIONS 1593} 1594 1595# Initializes built-in extensions 1596# Usage: 1597# antigen-ext-init 1598antigen-ext-init () { 1599 # Initialize extensions. unless in interactive mode. 1600 local ext 1601 for ext in ${(s/ /)_ANTIGEN_BUILTIN_EXTENSIONS}; do 1602 # Check if extension is loaded before intializing it 1603 (( $+functions[-antigen-$ext-init] )) && antigen-ext $ext 1604 done 1605} 1606# Initialize defer lib 1607-antigen-defer-init () { 1608 typeset -ga _DEFERRED_BUNDLE; _DEFERRED_BUNDLE=() 1609 if -antigen-interactive-mode; then 1610 return 1 1611 fi 1612} 1613 1614-antigen-defer-execute () { 1615 # Hooks antigen-bundle in order to defer its execution. 1616 antigen-bundle-defer () { 1617 _DEFERRED_BUNDLE+=("${(j: :)${@}}") 1618 return -1 # Stop right there 1619 } 1620 antigen-add-hook antigen-bundle antigen-bundle-defer replace 1621 1622 # Hooks antigen-apply in order to release hooked functions 1623 antigen-apply-defer () { 1624 WARN "Defer pre-apply" DEFER PRE-APPLY 1625 antigen-remove-hook antigen-bundle-defer 1626 1627 # Process all deferred bundles. 1628 local bundle 1629 for bundle in ${_DEFERRED_BUNDLE[@]}; do 1630 LOG "Processing deferred bundle: ${bundle}" DEFER 1631 antigen-bundle $bundle 1632 done 1633 1634 unset _DEFERRED_BUNDLE 1635 } 1636 antigen-add-hook antigen-apply antigen-apply-defer pre once 1637} 1638# Initialize lock lib 1639-antigen-lock-init () { 1640 # Default lock path. 1641 -antigen-set-default ANTIGEN_LOCK $ADOTDIR/.lock 1642 typeset -g _ANTIGEN_LOCK_PROCESS=false 1643 1644 # Use env variable to determine if we should load this extension 1645 -antigen-set-default ANTIGEN_MUTEX true 1646 # Set ANTIGEN_MUTEX to false to avoid loading this extension 1647 if [[ $ANTIGEN_MUTEX == true ]]; then 1648 return 0; 1649 fi 1650 1651 # Do not use mutex 1652 return 1; 1653} 1654 1655-antigen-lock-execute () { 1656 # Hook antigen command in order to check/create a lock file. 1657 # This hook is only run once then releases itself. 1658 antigen-lock () { 1659 LOG "antigen-lock called" 1660 # If there is a lock set up then we won't process anything. 1661 if [[ -f $ANTIGEN_LOCK ]]; then 1662 # Set up flag do the message is not repeated for each antigen-* command 1663 [[ $_ANTIGEN_LOCK_PROCESS == false ]] && printf "Antigen: Another process in running.\n" 1664 _ANTIGEN_LOCK_PROCESS=true 1665 # Do not further process hooks. For this hook to properly work it 1666 # should be registered first. 1667 return -1 1668 fi 1669 1670 WARN "Creating antigen-lock file at $ANTIGEN_LOCK" 1671 touch $ANTIGEN_LOCK 1672 } 1673 antigen-add-hook antigen antigen-lock pre once 1674 1675 # Hook antigen-apply in order to release .lock file. 1676 antigen-apply-lock () { 1677 WARN "Freeing antigen-lock file at $ANTIGEN_LOCK" 1678 unset _ANTIGEN_LOCK_PROCESS 1679 rm -f $ANTIGEN_LOCK &> /dev/null 1680 } 1681 antigen-add-hook antigen-apply antigen-apply-lock post once 1682} 1683# Initialize parallel lib 1684-antigen-parallel-init () { 1685 WARN "Init parallel extension" PARALLEL 1686 typeset -ga _PARALLEL_BUNDLE; _PARALLEL_BUNDLE=() 1687 if -antigen-interactive-mode; then 1688 return 1 1689 fi 1690} 1691 1692-antigen-parallel-execute() { 1693 WARN "Exec parallel extension" PARALLEL 1694 # Install bundles in parallel 1695 antigen-bundle-parallel-execute () { 1696 WARN "Parallel antigen-bundle-parallel-execute" PARALLEL 1697 typeset -a pids; pids=() 1698 local args pid 1699 1700 WARN "Gonna install in parallel ${#_PARALLEL_BUNDLE} bundles." PARALLEL 1701 # Do ensure-repo in parallel 1702 WARN "${_PARALLEL_BUNDLE}" PARALLEL 1703 typeset -Ua repositories # Used to keep track of cloned repositories to avoid 1704 # trying to clone it multiple times. 1705 for args in ${_PARALLEL_BUNDLE}; do 1706 typeset -A bundle; -antigen-parse-args 'bundle' ${=args} 1707 1708 if [[ ! -d ${bundle[dir]} && $repositories[(I)${bundle[url]}] == 0 ]]; then 1709 WARN "Install in parallel ${bundle[name]}." PARALLEL 1710 echo "Installing ${bundle[name]}!..." 1711 # $bundle[url]'s format is "url|branch" as to create "$ANTIGEN_BUNDLES/bundle/name-branch", 1712 # this way you may require multiple branches from the same repository. 1713 -antigen-ensure-repo "${bundle[url]}" > /dev/null &! 1714 pids+=($!) 1715 else 1716 WARN "Bundle ${bundle[name]} already cloned locally." PARALLEL 1717 fi 1718 1719 repositories+=(${bundle[url]}) 1720 done 1721 1722 # Wait for all background processes to end 1723 while [[ $#pids > 0 ]]; do 1724 for pid in $pids; do 1725 # `ps` may diplay an error message such "Signal 18 (CONT) caught by ps 1726 # (procps-ng version 3.3.9).", see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=732410 1727 if [[ $(ps -o pid= -p $pid 2>/dev/null) == "" ]]; then 1728 pids[$pids[(I)$pid]]=() 1729 fi 1730 done 1731 sleep .5 1732 done 1733 1734 builtin local bundle &> /dev/null 1735 for bundle in ${_PARALLEL_BUNDLE[@]}; do 1736 antigen-bundle $bundle 1737 done 1738 1739 1740 WARN "Parallel install done" PARALLEL 1741 } 1742 1743 # Hooks antigen-apply in order to release hooked functions 1744 antigen-apply-parallel () { 1745 WARN "Parallel pre-apply" PARALLEL PRE-APPLY 1746 #antigen-remove-hook antigen-pre-apply-parallel 1747 # Hooks antigen-bundle in order to parallel its execution. 1748 antigen-bundle-parallel () { 1749 TRACE "antigen-bundle-parallel: $@" PARALLEL 1750 _PARALLEL_BUNDLE+=("${(j: :)${@}}") 1751 } 1752 antigen-add-hook antigen-bundle antigen-bundle-parallel replace 1753 } 1754 antigen-add-hook antigen-apply antigen-apply-parallel pre once 1755 1756 antigen-apply-parallel-execute () { 1757 WARN "Parallel replace-apply" PARALLEL REPLACE-APPLY 1758 antigen-remove-hook antigen-bundle-parallel 1759 # Process all parallel bundles. 1760 antigen-bundle-parallel-execute 1761 1762 unset _PARALLEL_BUNDLE 1763 antigen-remove-hook antigen-apply-parallel-execute 1764 antigen-apply 1765 } 1766 antigen-add-hook antigen-apply antigen-apply-parallel-execute replace once 1767} 1768typeset -ga _ZCACHE_BUNDLE_SOURCE _ZCACHE_CAPTURE_BUNDLE 1769typeset -g _ZCACHE_CAPTURE_PREFIX 1770 1771# Generates cache from listed bundles. 1772# 1773# Iterates over _ANTIGEN_BUNDLE_RECORD and join all needed sources into one, 1774# if this is done through -antigen-load-list. 1775# Result is stored in ANTIGEN_CACHE. 1776# 1777# _ANTIGEN_BUNDLE_RECORD and fpath is stored in cache. 1778# 1779# Usage 1780# -zcache-generate-cache 1781# 1782# Returns 1783# Nothing. Generates ANTIGEN_CACHE 1784-antigen-cache-generate () { 1785 local -aU _fpath _PATH _sources 1786 local record 1787 1788 LOG "Gonna generate cache for $_ZCACHE_BUNDLE_SOURCE" 1789 for record in $_ZCACHE_BUNDLE_SOURCE; do 1790 record=${record:A} 1791 # LOG "Caching $record" 1792 if [[ -f $record ]]; then 1793 # Adding $'\n' as a suffix as j:\n: doesn't work inside a heredoc. 1794 if [[ $_ANTIGEN_THEME_COMPAT == true && "$record" == *.zsh-theme* ]]; then 1795 local compat="${record:A}.antigen-compat" 1796 echo "# Generated by Antigen. Do not edit!" >! "$compat" 1797 cat $record | sed -Ee '/\{$/,/^\}/!{ 1798 s/^local // 1799 }' >>! "$compat" 1800 record="$compat" 1801 fi 1802 _sources+=("source '${record}';"$'\n') 1803 elif [[ -d $record ]]; then 1804 _PATH+=("${record}") 1805 _fpath+=("${record}") 1806 fi 1807 done 1808 1809cat > $ANTIGEN_CACHE <<EOC 1810#-- START ZCACHE GENERATED FILE 1811#-- GENERATED: $(date) 1812#-- ANTIGEN v2.2.3 1813$(functions -- _antigen) 1814antigen () { 1815 local MATCH MBEGIN MEND 1816 [[ "\$ZSH_EVAL_CONTEXT" =~ "toplevel:*" || "\$ZSH_EVAL_CONTEXT" =~ "cmdarg:*" ]] && source "$_ANTIGEN_INSTALL_DIR/antigen.zsh" && eval antigen \$@; 1817 return 0; 1818} 1819typeset -gaU fpath path 1820fpath+=(${_fpath[@]}) path+=(${_PATH[@]}) 1821_antigen_compinit () { 1822 autoload -Uz compinit; compinit $ANTIGEN_COMPINIT_OPTS -d "$ANTIGEN_COMPDUMP"; compdef _antigen antigen 1823 add-zsh-hook -D precmd _antigen_compinit 1824} 1825autoload -Uz add-zsh-hook; add-zsh-hook precmd _antigen_compinit 1826compdef () {} 1827 1828if [[ -n "$ZSH" ]]; then 1829 ZSH="$ZSH"; ZSH_CACHE_DIR="$ZSH_CACHE_DIR" 1830fi 1831#--- BUNDLES BEGIN 1832${(j::)_sources} 1833#--- BUNDLES END 1834typeset -gaU _ANTIGEN_BUNDLE_RECORD; _ANTIGEN_BUNDLE_RECORD=($(print ${(qq)_ANTIGEN_BUNDLE_RECORD})) 1835typeset -g _ANTIGEN_CACHE_LOADED; _ANTIGEN_CACHE_LOADED=true 1836typeset -ga _ZCACHE_BUNDLE_SOURCE; _ZCACHE_BUNDLE_SOURCE=($(print ${(qq)_ZCACHE_BUNDLE_SOURCE})) 1837typeset -g _ANTIGEN_CACHE_VERSION; _ANTIGEN_CACHE_VERSION='v2.2.3' 1838 1839#-- END ZCACHE GENERATED FILE 1840EOC 1841 1842 { zcompile "$ANTIGEN_CACHE" } &! 1843 1844 # Compile config files, if any 1845 LOG "CHECK_FILES $ANTIGEN_CHECK_FILES" 1846 [[ $ANTIGEN_AUTO_CONFIG == true && -n $ANTIGEN_CHECK_FILES ]] && { 1847 echo ${(j:\n:)ANTIGEN_CHECK_FILES} >! "$ANTIGEN_RSRC" 1848 for rsrc in $ANTIGEN_CHECK_FILES; do 1849 zcompile $rsrc 1850 done 1851 } &! 1852 1853 return true 1854} 1855 1856# Initializes caching mechanism. 1857# 1858# Hooks `antigen-bundle` and `antigen-apply` in order to defer bundle install 1859# and load. All bundles are loaded from generated cache rather than dynamically 1860# as these are bundled. 1861# 1862# Usage 1863# -antigen-cache-init 1864# Returns 1865# Nothing 1866-antigen-cache-init () { 1867 if -antigen-interactive-mode; then 1868 return 1 1869 fi 1870 1871 _ZCACHE_CAPTURE_PREFIX=${_ZCACHE_CAPTURE_PREFIX:-"--zcache-"} 1872 _ZCACHE_BUNDLE_SOURCE=(); _ZCACHE_CAPTURE_BUNDLE=() 1873 1874 # Cache auto config files to check for changes (.zshrc, .antigenrc etc) 1875 -antigen-set-default ANTIGEN_AUTO_CONFIG true 1876 1877 # Default cache path. 1878 -antigen-set-default ANTIGEN_CACHE $ADOTDIR/init.zsh 1879 -antigen-set-default ANTIGEN_RSRC $ADOTDIR/.resources 1880 if [[ $ANTIGEN_CACHE == false ]]; then 1881 return 1 1882 fi 1883 1884 return 0 1885} 1886 1887-antigen-cache-execute () { 1888 # Main function. Deferred antigen-apply. 1889 antigen-apply-cached () { 1890 # TRACE "APPLYING CACHE" EXT 1891 # Auto determine check_files 1892 # There always should be 5 steps from original source as the correct way is to use 1893 # `antigen` wrapper not `antigen-apply` directly and it's called by an extension. 1894 LOG "TRACE: ${funcfiletrace}" 1895 if [[ $ANTIGEN_AUTO_CONFIG == true && $#ANTIGEN_CHECK_FILES -eq 0 ]]; then 1896 # Check common configuration file does exist. 1897 if [[ -f ${ZDOTDIR:-$HOME}/.zshrc ]]; then 1898 ANTIGEN_CHECK_FILES+=(${ZDOTDIR:-$HOME}/.zshrc) 1899 fi 1900 # TODO Fix: Fuzzy match shoud be replaced by a sane way to determine it. 1901 if [[ $#funcfiletrace -ge 6 ]]; then 1902 ANTIGEN_CHECK_FILES+=("${${funcfiletrace[6]%:*}##* }") 1903 fi 1904 fi 1905 1906 # Generate and compile cache 1907 -antigen-cache-generate 1908 [[ -f "$ANTIGEN_CACHE" ]] && source "$ANTIGEN_CACHE"; 1909 1910 # Commented out in order to have a working `cache-gen` command 1911 #unset _ZCACHE_BUNDLE_SOURCE 1912 unset _ZCACHE_CAPTURE_BUNDLE _ZCACHE_CAPTURE_FUNCTIONS 1913 1914 # Release all hooked functions 1915 antigen-remove-hook -antigen-load-env-cached 1916 antigen-remove-hook -antigen-load-source-cached 1917 antigen-remove-hook antigen-bundle-cached 1918 } 1919 1920 antigen-add-hook antigen-apply antigen-apply-cached post once 1921 1922 # Defer antigen-bundle. 1923 antigen-bundle-cached () { 1924 _ZCACHE_CAPTURE_BUNDLE+=("${(j: :)${@}}") 1925 } 1926 antigen-add-hook antigen-bundle antigen-bundle-cached pre 1927 1928 # Defer loading. 1929 -antigen-load-env-cached () { 1930 local bundle 1931 typeset -A bundle; bundle=($@) 1932 local location=${bundle[dir]}/${bundle[loc]} 1933 1934 # Load to path if there is no sourceable 1935 if [[ ${bundle[loc]} == "/" ]]; then 1936 _ZCACHE_BUNDLE_SOURCE+=("${location}") 1937 return 1938 fi 1939 1940 _ZCACHE_BUNDLE_SOURCE+=("${location}") 1941 } 1942 antigen-add-hook -antigen-load-env -antigen-load-env-cached replace 1943 1944 # Defer sourcing. 1945 -antigen-load-source-cached () { 1946 _ZCACHE_BUNDLE_SOURCE+=($@) 1947 } 1948 antigen-add-hook -antigen-load-source -antigen-load-source-cached replace 1949 1950 return 0 1951} 1952 1953# Generate static-cache file at $ANTIGEN_CACHE using currently loaded 1954# bundles from $_ANTIGEN_BUNDLE_RECORD 1955# 1956# Usage 1957# antigen-cache-gen 1958# 1959# Returns 1960# Nothing 1961antigen-cache-gen () { 1962 -antigen-cache-generate 1963} 1964#compdef _antigen 1965# Setup antigen's autocompletion 1966_antigen () { 1967 local -a _1st_arguments 1968 _1st_arguments=( 1969 'apply:Load all bundle completions' 1970 'bundle:Install and load the given plugin' 1971 'bundles:Bulk define bundles' 1972 'cleanup:Clean up the clones of repos which are not used by any bundles currently loaded' 1973 'cache-gen:Generate cache' 1974 'init:Load Antigen configuration from file' 1975 'list:List out the currently loaded bundles' 1976 'purge:Remove a cloned bundle from filesystem' 1977 'reset:Clears cache' 1978 'restore:Restore the bundles state as specified in the snapshot' 1979 'revert:Revert the state of all bundles to how they were before the last antigen update' 1980 'selfupdate:Update antigen itself' 1981 'snapshot:Create a snapshot of all the active clones' 1982 'theme:Switch the prompt theme' 1983 'update:Update all bundles' 1984 'use:Load any (supported) zsh pre-packaged framework' 1985 ); 1986 1987 _1st_arguments+=( 1988 'help:Show this message' 1989 'version:Display Antigen version' 1990 ) 1991 1992 __bundle() { 1993 _arguments \ 1994 '--loc[Path to the location <path-to/location>]' \ 1995 '--url[Path to the repository <github-account/repository>]' \ 1996 '--branch[Git branch name]' \ 1997 '--no-local-clone[Do not create a clone]' 1998 } 1999 __list() { 2000 _arguments \ 2001 '--simple[Show only bundle name]' \ 2002 '--short[Show only bundle name and branch]' \ 2003 '--long[Show bundle records]' 2004 } 2005 2006 2007 __cleanup() { 2008 _arguments \ 2009 '--force[Do not ask for confirmation]' 2010 } 2011 2012 _arguments '*:: :->command' 2013 2014 if (( CURRENT == 1 )); then 2015 _describe -t commands "antigen command" _1st_arguments 2016 return 2017 fi 2018 2019 local -a _command_args 2020 case "$words[1]" in 2021 bundle) 2022 __bundle 2023 ;; 2024 use) 2025 compadd "$@" "oh-my-zsh" "prezto" 2026 ;; 2027 cleanup) 2028 __cleanup 2029 ;; 2030 (update|purge) 2031 compadd $(type -f \-antigen-get-bundles &> /dev/null || antigen &> /dev/null; -antigen-get-bundles --simple 2> /dev/null) 2032 ;; 2033 theme) 2034 compadd $(type -f \-antigen-get-themes &> /dev/null || antigen &> /dev/null; -antigen-get-themes 2> /dev/null) 2035 ;; 2036 list) 2037 __list 2038 ;; 2039 esac 2040} 2041zmodload zsh/datetime 2042ANTIGEN_DEBUG_LOG=${ANTIGEN_DEBUG_LOG:-${ADOTDIR:-$HOME/.antigen}/debug.log} 2043LOG () { 2044 local PREFIX="[LOG][${EPOCHREALTIME}]" 2045 echo "${PREFIX} ${funcfiletrace[1]}\n${PREFIX} $@" >> $ANTIGEN_DEBUG_LOG 2046} 2047 2048ERR () { 2049 local PREFIX="[ERR][${EPOCHREALTIME}]" 2050 echo "${PREFIX} ${funcfiletrace[1]}\n${PREFIX} $@" >> $ANTIGEN_DEBUG_LOG 2051} 2052 2053WARN () { 2054 local PREFIX="[WRN][${EPOCHREALTIME}]" 2055 echo "${PREFIX} ${funcfiletrace[1]}\n${PREFIX} $@" >> $ANTIGEN_DEBUG_LOG 2056} 2057 2058TRACE () { 2059 local PREFIX="[TRA][${EPOCHREALTIME}]" 2060 echo "${PREFIX} ${funcfiletrace[1]}\n${PREFIX} $@\n${PREFIX} ${(j:\n:)funcstack}" >> $ANTIGEN_DEBUG_LOG 2061} 2062-antigen-env-setup 2063