Skip to content

Instantly share code, notes, and snippets.

@awalterschulze
Created August 25, 2015 08:07
Show Gist options
  • Save awalterschulze/c2a483a04ea655fd18d0 to your computer and use it in GitHub Desktop.
Save awalterschulze/c2a483a04ea655fd18d0 to your computer and use it in GitHub Desktop.
Automatically Changing Environments

Here is the enterprise version

https://github.com/cxreg/smartcd

I only needed this

https://github.com/alecthomas/ondir

Macs can brew install ondir, I guess there must be some linux install.

Then you add the script.sh contents to your .bash_profile

Next you create a ~/.ondirrc file

enter ~/code/letmegrpc
  export GOPATH=$ONDIRWD
  echo "Switched GOPATH to $GOPATH"
  export PATH=$GOPATH/bin:$PATH
  echo "Prepended $GOPATH/bin to PATH"

enter ~/code/gopath
  export GOPATH=$ONDIRWD
  echo "Switched GOPATH to $GOPATH"
  export PATH=$GOPATH/bin:$PATH
  echo "Prepended $GOPATH/bin to PATH"

Log out and Log into your console

Now when you cd to a folder your GOPATH and PATH will be set automatically.

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