Skip to content

Instantly share code, notes, and snippets.

@nilium
Created February 26, 2015 18:34
Show Gist options
  • Save nilium/4885518f79da22f8e30f to your computer and use it in GitHub Desktop.
Save nilium/4885518f79da22f8e30f to your computer and use it in GitHub Desktop.
Go wrapper script
#!/bin/sh
#
# Forwarding utility for go.
# Puts any directory with a .go-root file into the GOPATH then launches go.
#
# Assumes you have a go binary already in your path.
#
# Depends on:
# https://github.com/nilium/gopath
# https://github.com/nilium/realpath
#
export GOPATH="`gopath -to-root "$(realpath .)"`"
GOBIN="$(which -a go | sed -e '2q;d')"
debugging=
# check for gopath args
while [[ 1 ]] ; do
case "$1" in
"--go-bin-path")
GOBIN="$2"
shift; shift
continue
;;
"--echo-gopath"|"-echo-gopath")
debugging=1
echo "$GOPATH"
shift
continue
;;
"--echo-gobin"|"-echo-gobin")
debugging=1
echo "$GOBIN"
shift
continue
;;
esac
break
done
if [[ -n $debugging ]] ; then
exit 0
fi
if [[ -x "$GOBIN" && "$GOBIN" != "$0" ]] ; then
"$GOBIN" "$@"
else
echo "No valid 'go' executable in PATH -- tried '$GOBIN'" 1>&2
exit 1
fi
# vim: set ts=4 sw=4 et :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment