Skip to content

Instantly share code, notes, and snippets.

@isurfer21
Created September 20, 2019 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isurfer21/be1ee6804818b1ac267e6ff159f26ed5 to your computer and use it in GitHub Desktop.
Save isurfer21/be1ee6804818b1ac267e6ff159f26ed5 to your computer and use it in GitHub Desktop.
Golang package cleaner
#!/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