Last active
May 26, 2022 03:13
-
-
Save wbailey/88983f497089de5f09b8 to your computer and use it in GitHub Desktop.
Automatically add the current directory to the GOPATH when changing into it
This file contains 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
# GOPATH helper | |
goPathFile="$HOME/.gopathsrc" | |
if [ -f "$goPathFile" ]; then | |
source "$goPathFile" | |
fi |
This file contains 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
CHECK_FILENAME=.gopath | |
setGoPath() { | |
if [ -f "$PWD/$CHECK_FILENAME" ]; then | |
if ! [[ "$GOPATH" =~ (^|:)"$PWD"(:|$) ]]; then | |
echo "Adding $PWD to GOPATH" | |
export GOPATH=$GOPATH:$PWD | |
echo $GOPATH | |
fi | |
fi | |
} | |
if [ "$PROMPT_COMMAND" != "*setGoPath*" ]; then | |
export PREV_PROMPT_COMMAND=$PROMPT_COMMAND | |
export PROMPT_COMMAND="$PROMPT_COMMAND; setGoPath" | |
fi |
As you wish. I would not dispute about the "foregoing maintenance complexity" because it depends on the observer. Mind though that the longer the path the more time is required to process things and more chances for ambiguity.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@minherz There is no downside to having repeated elements in the path while foregoing the complexity of maintaining the unique elements you are suggesting.