Skip to content

Instantly share code, notes, and snippets.

@mishak87
Last active April 25, 2016 09:35
Show Gist options
  • Save mishak87/64e791c16d6cc6e2b0a3f3fe2b806d75 to your computer and use it in GitHub Desktop.
Save mishak87/64e791c16d6cc6e2b0a3f3fe2b806d75 to your computer and use it in GitHub Desktop.
Open Go GVM projects and others in Atom

Assuming that projects are organized like this ~/workspace[/<group>[/<vendor>]]/<project>.

Project acme/api is written in Go. It will open atom with all projects and env set for acme/api.

project acme/{api,web} todo
#!/bin/bash
set -euo pipefail
readonly WORKSPACE="$HOME/workspace"
readonly DEFAULT_PROJECT="standup.team/core"
readonly IDE="atom-beta"
readonly GO_VERSION="1.6.1"
main () {
if [ $# -eq 0 ]; then
set -- "$DEFAULT_PROJECT"
fi
local paths=()
local foundEnvDependend=0
while [ $# -gt 0 ]; do
local project=$1; shift
local path
path=$(find "$WORKSPACE" -maxdepth 3 -type d -print0 | grep -FzZ "$project" | sort -z | head -z -n1 || echo -n "")
if [ -z "$path" ]; then
continue
fi
paths+=("$path")
if [ $foundEnvDependend -eq 1 ]; then
continue
fi
if [ "$(find "$path" -type f -name '*.go' | wc -l)" -gt 0 ]; then
foundEnvDependend=1
set +u
[[ -s "$HOME/.gvm/scripts/gvm" ]] && source "$HOME/.gvm/scripts/gvm"
gvm use "$GO_VERSION"
set -u
export GOPATH="$path:$GOPATH"
fi
done
if [ "${#paths[@]}" -eq 0 ]; then
echo "No projects found." 1>&2
exit 1
fi
"$IDE" "${paths[@]}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment