Skip to content

Instantly share code, notes, and snippets.

@danp
Last active September 10, 2015 14:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danp/c4f3d146ae4027a69bc1 to your computer and use it in GitHub Desktop.
Save danp/c4f3d146ae4027a69bc1 to your computer and use it in GitHub Desktop.
godep-aware goimports and more
#!/bin/sh
# for use with emacs/vim/etc as goimports and goflymake
#
# I use it with config like:
#
# (setenv "GOPATH" (expand-file-name "~/Projects/go"))
# (setenv "PATH" "~/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:~/Projects/go/bin:/usr/local/go/bin")
# (setq exec-path (append exec-path (list (expand-file-name "~/Projects/go/bin") "/usr/local/go/bin")))
#
# and put this script as `goimports` in ~/bin + symlink `goflymake` to it
# with the real `goimports` and `goflymake` in $GOPATH/bin
if [ -z "$GOPATH" ]; then
echo "Missing GOPATH" >&2
exit 1
fi
orig_gopath="$GOPATH"
godep_path=$(godep path 2>/dev/null)
if [ $? -eq 0 ]; then
export GOPATH="$godep_path:$orig_gopath"
fi
exec "$orig_gopath/bin/$(basename "$0")" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment