Skip to content

Instantly share code, notes, and snippets.

@RobRuana
Last active July 24, 2023 10:51
Show Gist options
  • Save RobRuana/7cda375014e0f699fba1 to your computer and use it in GitHub Desktop.
Save RobRuana/7cda375014e0f699fba1 to your computer and use it in GitHub Desktop.
Change $GOPATH to current directory to quickly switch between Go workspaces
#!/bin/bash -l
# Save this file in /usr/local/bin and chmod a+x for easy access
# Execute gohere to switch $GOPATH to current directory
# Type exit to switch back
# Example usage:
# $ echo $GOPATH
#
# $ gohere
# (go@directory) $ echo $GOPATH
# /path/to/directory
# (go@directory) $ exit
# exit
# $ echo $GOPATH
#
# $
# Set $GOPATH to current directory
export GOPATH=${PWD}
# Update command prompt to remind you which workspace you're using.
# This requires that your .bashrc looks for the $PROMPT_PREFIX variable
export PROMPT_PREFIX="(go@`basename ${PWD}`)"
# Start a new bash shell to inherit $GOPATH
bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment