Created
September 20, 2019 05:05
-
-
Save isurfer21/be1ee6804818b1ac267e6ff159f26ed5 to your computer and use it in GitHub Desktop.
Golang package cleaner
This file contains 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
#!/usr/bin/env sh | |
goclean() { | |
local pkg=$1; shift || return 1 | |
local ost | |
local cnt | |
local scr | |
echo "Clean removes object files from package source directories (ignore error)" | |
go clean -i $pkg | |
echo "Set local variables" | |
if [ "$(uname -m)" == "x86_64" ]; then | |
ost="$(uname)"; | |
ost="${ost}_amd64" | |
cnt="${pkg//[^\/]}" | |
fi | |
echo "Delete the source directory and compiled package directory(ies)" | |
if (("${#cnt}" == "2")); then | |
rm -rf "${GOPATH%%:*}/src/${pkg%/*}" | |
rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*}" | |
elif (("${#cnt}" > "2")); then | |
rm -rf "${GOPATH%%:*}/src/${pkg%/*/*}" | |
rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*/*}" | |
fi | |
echo "Reload the current shell" | |
if [ -e "~/.bashrc" ]; then | |
source ~/.bashrc | |
elif [ -e "~/.bash_profile" ]; then | |
source ~/.bash_profile | |
fi | |
} | |
if [[ "$1" == "" ]]; then | |
echo "Package name is missing!" | |
else | |
goclean $1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment