Created
November 26, 2016 21:27
-
-
Save phemmer/81922b32aa61b6707bd9940a2f11a1e4 to your computer and use it in GitHub Desktop.
GDM wrapper for not mucking with shared $GOPATH
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 | |
self_path="$(readlink -f "$0")" | |
self_dir="${self_path%/*}" | |
#unset PWD # screws with go package path detection | |
IFS=$'\n' read -d '' -a gdms < <(which -a gdm) | |
realgdm= | |
foundself= | |
for gdm in "${gdms[@]}"; do | |
if [[ -n "$foundself" ]]; then | |
realgdm="$gdm" | |
break | |
fi | |
if [[ "$(readlink -f "$gdm")" == "$self_path" ]]; then | |
foundself=1 | |
fi | |
done | |
if [[ -z "$realgdm" ]]; then | |
echo "gdm not found" >&2 | |
exit 1 | |
fi | |
projdir=$PWD | |
while [[ ! -e $projdir/Godeps ]] && [[ "$projdir" != "" ]]; do | |
projdir=${projdir%/*} | |
done | |
if [[ "$projdir" == "" ]]; then | |
projdir=$PWD | |
fi | |
import_path=$(cd $projdir && go list -f '{{.ImportPath}}' .) | |
mkdir -p "$projdir/.go/src/${import_path%/*}" | |
ln -sf "$projdir" "$projdir/.go/src/${import_path}" | |
twd=/tmp/.gdm_$$ | |
ln -sf "$projdir/.go" $twd | |
trap "rm -f $twd" EXIT | |
GOPATH="$twd:$GOPATH" | |
cd "$twd/src/$import_path/${PWD#$projdir}" | |
if [[ "$1" == exec ]]; then | |
shift | |
"$@" | |
exit $? | |
fi | |
$realgdm "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment