Commit 499c0dd5dc947ec7cfe1e94e5096b6cd6951beb1
1 parent
3e16c47090
Added some comments.
Showing 1 changed file with 25 additions and 2 deletions Side-by-side Diff
antigen.zsh
| ... | ... | @@ -53,8 +53,10 @@ antigen-bundle () { |
| 53 | 53 | # Add it to the record. |
| 54 | 54 | _ANTIGEN_BUNDLE_RECORD="$_ANTIGEN_BUNDLE_RECORD\n$url $loc $btype $branch" |
| 55 | 55 | |
| 56 | + # Ensure a clone exists for this repo. | |
| 56 | 57 | -antigen-ensure-repo "$url" "$branch" |
| 57 | 58 | |
| 59 | + # Load the plugin. | |
| 58 | 60 | -antigen-load "$url" "$loc" "$btype" "$branch" |
| 59 | 61 | |
| 60 | 62 | } |
| ... | ... | @@ -89,14 +91,19 @@ antigen-update () { |
| 89 | 91 | # TODO: Memoize? |
| 90 | 92 | local url="$1" |
| 91 | 93 | local branch="$2" |
| 92 | - echo -n $ADOTDIR/repos/ | |
| 93 | 94 | |
| 95 | + # The branched_url will be the same as the url itself, unless there is no | |
| 96 | + # branch specified. | |
| 94 | 97 | local branched_url="$url" |
| 95 | 98 | |
| 99 | + # If a branch is specified, i.e., branch is not `-`, append it to the url, | |
| 100 | + # separating with a pipe character. | |
| 96 | 101 | if [[ "$branch" != - ]]; then |
| 97 | 102 | branched_url="$branched_url|$branch" |
| 98 | 103 | fi |
| 99 | 104 | |
| 105 | + # Echo the full path to the clone directory. | |
| 106 | + echo -n $ADOTDIR/repos/ | |
| 100 | 107 | echo "$branched_url" | sed \ |
| 101 | 108 | -e 's/\.git$//' \ |
| 102 | 109 | -e 's./.-SLASH-.g' \ |
| ... | ... | @@ -118,22 +125,31 @@ antigen-update () { |
| 118 | 125 | |
| 119 | 126 | -antigen-ensure-repo () { |
| 120 | 127 | |
| 128 | + # Ensure that a clone exists for the given repo url and branch. If the first | |
| 129 | + # argument is `--update` and if a clone already exists for the given repo | |
| 130 | + # and branch, it is pull-ed, i.e., updated. | |
| 131 | + | |
| 132 | + # Check if we have to update. | |
| 121 | 133 | local update=false |
| 122 | 134 | if [[ $1 == --update ]]; then |
| 123 | 135 | update=true |
| 124 | 136 | shift |
| 125 | 137 | fi |
| 126 | 138 | |
| 139 | + # Get the clone's directory as per the given repo url and branch. | |
| 127 | 140 | local url="$1" |
| 128 | 141 | local branch="$2" |
| 129 | 142 | local clone_dir="$(-antigen-get-clone-dir $url $branch)" |
| 130 | 143 | |
| 144 | + # Clone if it doesn't already exist. | |
| 131 | 145 | if [[ ! -d $clone_dir ]]; then |
| 132 | 146 | git clone "$url" "$clone_dir" |
| 133 | 147 | elif $update; then |
| 148 | + # Pull changes if update requested. | |
| 134 | 149 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" pull |
| 135 | 150 | fi |
| 136 | 151 | |
| 152 | + # If its a specific branch that we want, checkout that branch. | |
| 137 | 153 | if [[ "$branch" != - ]]; then |
| 138 | 154 | git --git-dir "$clone_dir/.git" --work-tree "$clone_dir" \ |
| 139 | 155 | checkout "$branch" |
| ... | ... | @@ -148,6 +164,7 @@ antigen-update () { |
| 148 | 164 | local btype="$3" |
| 149 | 165 | local branch="$4" |
| 150 | 166 | |
| 167 | + # The full location where the plugin is located. | |
| 151 | 168 | local location="$(-antigen-get-clone-dir "$url" "$branch")/$loc" |
| 152 | 169 | |
| 153 | 170 | if [[ $btype == theme ]]; then |
| ... | ... | @@ -162,20 +179,24 @@ antigen-update () { |
| 162 | 179 | # FIXME: I don't know. Looks very very ugly. Needs a better |
| 163 | 180 | # implementation once tests are ready. |
| 164 | 181 | local script_loc="$(ls "$location" | grep -m1 '.plugin.zsh$')" |
| 182 | + | |
| 165 | 183 | if [[ -f $script_loc ]]; then |
| 166 | 184 | # If we have a `*.plugin.zsh`, source it. |
| 167 | 185 | source "$script_loc" |
| 186 | + | |
| 168 | 187 | elif [[ ! -z "$(ls "$location" | grep -m1 '.zsh$')" ]]; then |
| 169 | 188 | # If there is no `*.plugin.zsh` file, source *all* the `*.zsh` |
| 170 | 189 | # files. |
| 171 | 190 | for script ($location/*.zsh) source "$script" |
| 191 | + | |
| 172 | 192 | elif [[ ! -z "$(ls "$location" | grep -m1 '.sh$')" ]]; then |
| 173 | 193 | # If there are no `*.zsh` files either, we look for and source any |
| 174 | 194 | # `*.sh` files instead. |
| 175 | 195 | for script ($location/*.sh) source "$script" |
| 196 | + | |
| 176 | 197 | fi |
| 177 | 198 | |
| 178 | - # Add to $fpath, for completion(s) | |
| 199 | + # Add to $fpath, for completion(s). | |
| 179 | 200 | fpath=($location $fpath) |
| 180 | 201 | |
| 181 | 202 | fi |
| ... | ... | @@ -184,6 +205,8 @@ antigen-update () { |
| 184 | 205 | |
| 185 | 206 | antigen-cleanup () { |
| 186 | 207 | |
| 208 | + # Cleanup unused repositories. | |
| 209 | + | |
| 187 | 210 | if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then |
| 188 | 211 | echo "You don't have any bundles." |
| 189 | 212 | return 0 |