Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 60 lines (53 sloc) 1.525 kb
#!/bin/bash
# This script passes all arguments through directly to the 'go' command, possibly altering the $GOPATH
# variable beforehand. This is done by checking for the presence of a file called .glp in the current
# directory or any ancestor directory recursively up to / -- if the file does not exist, then $GOPATH is left
# unchanged. If the file exists, then $GOPATH is set so that it contains the following paths:
#
# * The current directory
# * All directories listed in .glp, in order
#
# Each line of .glp must be the name of a directory that exists. It may be an absolute or relative path. A
# typical use case will have a single directory (usually called vendor/, or third_party/, or similar).
set -e
append_fullpath() {
pushd $1 > /dev/null
fullpath=`pwd -P`
popd > /dev/null
if [[ -z $newpath ]]; then
newpath=$fullpath
else
newpath="${newpath}:${fullpath}"
fi
}
# This needs to be run from the directory containing .glp
process_glp_file() {
newpath=""
append_fullpath .
while read -r dir; do
if [[ -z $dir ]]; then
continue
fi
if [[ ! -d $dir ]]; then
echo "go-localpath error: the directory '${dir}' indicated by .glp in `pwd` does not exist."
exit 1
fi
append_fullpath $dir
done < ./.glp
export GOPATH=$newpath
}
# Check for .glp in the cwd and on up.
cwd=`pwd`
while true; do
oldcwd=`pwd`
if [[ -f ./.glp ]]; then
process_glp_file
break
fi
cd ..
if [[ `pwd` = "$oldcwd" ]]; then
break
fi
done
cd $cwd
go "$@"
Jump to Line
Something went wrong with that request. Please try again.