Last active
December 16, 2015 04:29
-
-
Save blinsay/5377663 to your computer and use it in GitHub Desktop.
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 | |
# Apparently this doesn't work. :(((((((((((( | |
_path_remove () { export PATH=`echo -n $PATH | awk -v RS=: -v ORS=: '$0 != "'$1'"' | sed 's/:$//'`; } | |
goenv() { | |
new_env=${1:-`pwd`} | |
old_env=$GOPATH | |
if [[ -z $old_env ]]; then | |
_path_remove $old_env/bin | |
fi | |
export GOPATH=$new_env | |
export PATH="$PATH:$new_env/bin" | |
} |
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
# This works happily. | |
function goenv() { | |
case $1 in | |
"list") | |
echo "-> gopath=$GOPATH" | |
;; | |
*) | |
_set_goenv $@ | |
;; | |
esac | |
} | |
function _set_goenv() { | |
new_env=$1 | |
old_env=$GOPATH | |
if [[ -n $old_env ]]; then | |
old_bin_path=${old_env}/bin | |
path=(${path#$old_bin_path}) | |
fi | |
if [[ -z $new_env ]]; then | |
new_env=$(pwd) | |
fi | |
path+=($new_env/bin) | |
GOPATH=$new_env | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment