Commit 0b32bec279b0a78a01729cb848e7bd2921f4bb13
1 parent
575a537db9
bundle-cleanup command now works.
The bundle-cleanup, now cleans up unused clones of repositories, to which no plugin is referring to.
Showing 1 changed file with 48 additions and 36 deletions Side-by-side Diff
antigen.zsh
| ... | ... | @@ -67,6 +67,17 @@ bundle () { |
| 67 | 67 | -e 's.:.-COLON-.g' |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | +-antigen-get-clone-url () { | |
| 71 | + # Takes a repo's clone dir and gives out the repo's original url that was | |
| 72 | + # used to create the given directory path. | |
| 73 | + # TODO: Memoize? | |
| 74 | + echo "$1" | sed \ | |
| 75 | + -e "s:^$ADOTDIR/repos/::" \ | |
| 76 | + -e 's/$/.git/' \ | |
| 77 | + -e 's.-SLASH-./.g' \ | |
| 78 | + -e 's.-COLON-.:.g' | |
| 79 | +} | |
| 80 | + | |
| 70 | 81 | -antigen-ensure-repo () { |
| 71 | 82 | |
| 72 | 83 | local update=false |
| ... | ... | @@ -100,42 +111,6 @@ bundle-update () { |
| 100 | 111 | done |
| 101 | 112 | } |
| 102 | 113 | |
| 103 | -bundle-cleanup () { | |
| 104 | - | |
| 105 | - if [[ ! -d "$ADOTDIR/bundles" || \ | |
| 106 | - "$(ls "$ADOTDIR/bundles/" | wc -l)" == 0 ]]; then | |
| 107 | - echo "You don't have any bundles." | |
| 108 | - return 0 | |
| 109 | - fi | |
| 110 | - | |
| 111 | - # Find directores in ADOTDIR/bundles, that are not in the bundles record. | |
| 112 | - local unidentified_bundles="$(comm -13 \ | |
| 113 | - <(-bundle-echo-record | awk '{print $1}' | sort) \ | |
| 114 | - <(ls -1 "$ADOTDIR/bundles"))" | |
| 115 | - | |
| 116 | - if [[ -z $unidentified_bundles ]]; then | |
| 117 | - echo "You don't have any unidentified bundles." | |
| 118 | - return 0 | |
| 119 | - fi | |
| 120 | - | |
| 121 | - echo The following bundles are not recorded: | |
| 122 | - echo "$unidentified_bundles" | sed 's/^/ /' | |
| 123 | - | |
| 124 | - echo -n '\nDelete them all? [y/N] ' | |
| 125 | - if read -q; then | |
| 126 | - echo | |
| 127 | - echo | |
| 128 | - echo "$unidentified_bundles" | while read name; do | |
| 129 | - echo -n Deleting $name... | |
| 130 | - rm -rf "$ADOTDIR/bundles/$name" | |
| 131 | - echo ' done.' | |
| 132 | - done | |
| 133 | - else | |
| 134 | - echo | |
| 135 | - echo Nothing deleted. | |
| 136 | - fi | |
| 137 | -} | |
| 138 | - | |
| 139 | 114 | bundle-load () { |
| 140 | 115 | |
| 141 | 116 | local url="$1" |
| ... | ... | @@ -170,6 +145,43 @@ bundle-load () { |
| 170 | 145 | |
| 171 | 146 | } |
| 172 | 147 | |
| 148 | +bundle-cleanup () { | |
| 149 | + | |
| 150 | + if [[ ! -d "$ADOTDIR/repos" || -z "$(ls "$ADOTDIR/repos/")" ]]; then | |
| 151 | + echo "You don't have any bundles." | |
| 152 | + return 0 | |
| 153 | + fi | |
| 154 | + | |
| 155 | + # Find directores in ADOTDIR/repos, that are not in the bundles record. | |
| 156 | + local unused_clones="$(comm -13 \ | |
| 157 | + <(-bundle-echo-record | awk '{print $1}' | sort -u) \ | |
| 158 | + <(ls "$ADOTDIR/repos" | while read line; do | |
| 159 | + -antigen-get-clone-url "$line" | |
| 160 | + done))" | |
| 161 | + | |
| 162 | + if [[ -z $unused_clones ]]; then | |
| 163 | + echo "You don't have any unidentified bundles." | |
| 164 | + return 0 | |
| 165 | + fi | |
| 166 | + | |
| 167 | + echo 'You have clones for the following repos, but are not used.' | |
| 168 | + echo "$unused_clones" | sed 's/^/ /' | |
| 169 | + | |
| 170 | + echo -n '\nDelete them all? [y/N] ' | |
| 171 | + if read -q; then | |
| 172 | + echo | |
| 173 | + echo | |
| 174 | + echo "$unused_clones" | while read url; do | |
| 175 | + echo -n "Deleting clone for $url..." | |
| 176 | + rm -rf "$(-antigen-get-clone-dir $url)" | |
| 177 | + echo ' done.' | |
| 178 | + done | |
| 179 | + else | |
| 180 | + echo | |
| 181 | + echo Nothing deleted. | |
| 182 | + fi | |
| 183 | +} | |
| 184 | + | |
| 173 | 185 | bundle-lib () { |
| 174 | 186 | bundle --loc=lib |
| 175 | 187 | } |