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 "$@" |