Created
January 5, 2016 17:01
-
-
Save phemmer/01c9e3fda97537dc7bfb to your computer and use it in GitHub Desktop.
git clean stale archives
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| eval "$(go env)" | |
| function clean_gopath() { | |
| gopath="$1" | |
| pkgpath="$gopath/pkg/${GOHOSTOS}_$GOHOSTARCH" | |
| if [[ ! -e "$pkgpath" ]]; then | |
| return | |
| fi | |
| while IFS='' read a; do | |
| pkg="${a%.a}" | |
| if [[ ! -e "$gopath/src/$pkg" ]]; then | |
| continue | |
| fi | |
| find "$gopath/src/$pkg" -maxdepth 1 \( -path "$gopath/src/$pkg" -o \( -name '*.go' \! -name '*_test.go' \) \) -newer "$pkgpath/$a" \( -exec rm "$pkgpath/$a" \; -o -true \) -quit & | |
| done < <(find "$pkgpath" -name '*.a' -printf '%P\n') | |
| wait | |
| } | |
| declare -A checked | |
| IFS=: read -d '' -a gopaths < <(printf "%s" "$GOPATH") | |
| for gopath in "${gopaths[@]}"; do | |
| if [[ -n "${checked[$gopath]}" ]]; then | |
| continue | |
| fi | |
| checked["$gopath"]=1 | |
| clean_gopath "$gopath" & | |
| done | |
| wait |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment