Skip to content

Instantly share code, notes, and snippets.

@rahulg
Last active December 18, 2015 23:08
Show Gist options
  • Save rahulg/5859285 to your computer and use it in GitHub Desktop.
Save rahulg/5859285 to your computer and use it in GitHub Desktop.
Initialise a golang project by setting up the directory structure and creating the virtualenv-like activate script.
#!/bin/bash
if [ $# -ne 1 ]; then
echo "Usage: $(basename "${0}") <project>"
exit 1
fi
mkdir -p "${1}"/{,src,pkg,bin}
cat << 'EOF' > "${1}/activate"
if [ -z "$BASH_VERSION" ]; then
export GOPATH="$(cd "$(dirname "${0}" )" && pwd)"
else
export GOPATH="$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd)"
fi
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
}
EOF
cat << 'EOF' > "${1}/activate.fish"
set -x GOPATH (dirname (status -f))
function gcd
cd $GOPATH
end
function deactivate
set -e GOPATH
functions -e deactivate
end
EOF
cat << 'EOF' > "${1}/$(basename "${1}").sublime-project"
{
"folders":
[
{
"path": "."
}
],
"settings": {
"GoSublime": {
"env": {
"GOPATH": "$PWD"
}
}
}
}
EOF
@olenhad
Copy link

olenhad commented Jun 27, 2013

/sidenote github's slightly screwed syntax highlighting makes me feel better about arc.

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