Skip to content

Instantly share code, notes, and snippets.

@rahulg
Created June 25, 2013 14:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rahulg/5858911 to your computer and use it in GitHub Desktop.
Save rahulg/5858911 to your computer and use it in GitHub Desktop.
Virtualenv-like activate & deactivate for golang. Source this file the normal way from bash to activate the GOPATH, deactivate to deactivate.
export GOPATH="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"
export OLDPS1=$PS1
export PS1="[go:$(basename $GOPATH)] $PS1"
alias gcd="cd $GOPATH"
deactivate() {
export PS1=$OLDPS1
unset GOPATH
unset OLDPS1
unalias gcd
unset deactivate
}
@xiongchiamiov
Copy link

I forked this to add builtin to the cd. This prevents issues when cd is aliased to something else - for instance, cd() { builtin cd $1 && ls }.

@xiongchiamiov
Copy link

Oh, and I made it work in zsh, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment