-
-
Save kyleburton/9d101bc9814054af900ee5cbea4bbe04 to your computer and use it in GitHub Desktop.
linux project launcher (eg: az/ht)
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
#!/usr/bin/env bash | |
set -eEu -o pipefail | |
# set -x | |
WORKSPACES="project-web project-admin cider-scratchpad lambda-handler api-tests terraform cypress-web cypress-admin" | |
COMMANDS="urls reset gist shutdown stop workspaces commands all" | |
function workspace-name-for-abbreviation { | |
case "$1" in | |
cypress-web) | |
echo "cypress-web" | |
;; | |
cypress-admin) | |
echo "cypress-admin" | |
;; | |
web|project-web) | |
echo "project-web" | |
;; | |
lambda|lambda-handler) | |
echo "lambda-handler" | |
;; | |
admin|project-admin) | |
echo "project-admin" | |
;; | |
cider|scratchpad|cider-scratchpad) | |
echo "cider-scratchpad" | |
;; | |
tests|api-tests) | |
echo "api-tests" | |
;; | |
terraform) | |
echo "terraform" | |
;; | |
*) | |
return 1 | |
esac | |
} | |
function workdir-for-workspace { | |
case "$1" in | |
cypress-web) | |
echo "$HOME/code/snapclean.me/projectwestla.com/project-web/cypress" | |
;; | |
cypress-admin) | |
echo "$HOME/code/snapclean.me/projectwestla.com/project-admin/cypress" | |
;; | |
project-web) | |
echo "$HOME/code/snapclean.me/projectwestla.com/project-web" | |
;; | |
lambda-handler) | |
echo "$HOME/code/snapclean.me/projectwestla.com/lambda-handler" | |
;; | |
project-admin) | |
echo "$HOME/code/snapclean.me/projectwestla.com/project-admin" | |
;; | |
cider-scratchpad) | |
echo "$HOME/code/snapclean.me/projectwestla.com/cider-scratchpad" | |
;; | |
api-tests) | |
echo "$HOME/code/snapclean.me/projectwestla.com/api-tests" | |
;; | |
terraform) | |
echo "$HOME/code/snapclean.me/projectwestla.com/terraform" | |
;; | |
*) | |
return 1 | |
esac | |
} | |
function desktop-num-for-workspace { | |
case "$1" in | |
cypress-web|cypress-admin|terraform) | |
echo 1 | |
;; | |
project-web) | |
echo 2 | |
;; | |
lambda-handler) | |
echo 3 | |
;; | |
project-admin) | |
echo 4 | |
;; | |
cider-scratchpad) | |
echo 5 | |
;; | |
api-tests) | |
echo 6 | |
;; | |
*) | |
echo 1;; | |
esac | |
} | |
function xte.goto-desktop { | |
local desktop="$1" | |
xte "keydown Alt_L" "key $desktop" "keyup Alt_L" | |
} | |
function cmd.attach-tmux { | |
local workspace workdir desktop | |
workspace="$(workspace-name-for-abbreviation "$1")" | |
workdir="$(workdir-for-workspace "$workspace")" | |
desktop="$(desktop-num-for-workspace "$workspace")" | |
xte.goto-desktop "$desktop" | |
if tmux list-sessions | grep -q "$workspace:"; then | |
gnome-terminal -- tmux attach -t "$workspace" | |
xte "keydown Alt_L" "key Home" "keyup Alt_L" | |
return | |
fi | |
echo "Starting tmux $workspace on desktop $desktop in pwd=$workdir" | |
cd "$workdir" | |
tmux start-server | |
if [[ -f ./.tmux.conf ]]; then | |
echo gnome-terminal -- tmux source-file ./.tmux.conf | |
gnome-terminal -- tmux start-server \; source-file ./.tmux.conf | |
else | |
echo gnome-terminal -- tmux attach -t "$workspace" | |
gnome-terminal -- tmux attach -t "$workspace" | |
fi | |
xte "keydown Alt_L" "key Home" "keyup Alt_L" | |
} | |
function cmd.open-url { | |
local url | |
url="$1" | |
xte.goto-desktop "2" | |
google-chrome "$url" & | |
} | |
function cmd.open-all-urls { | |
cmd.open-url "http://localhost:8280/admin/" | |
sleep 2 | |
cmd.open-url "http://localhost:8281/" | |
} | |
function cmd.open-all { | |
local workspace workspaces | |
workspaces="$WORKSPACES" | |
workspace="${1:-}" | |
if [[ -n "$workspace" ]]; then | |
workspaces="$(workspace-name-for-abbreviation "$workspace")" | |
fi | |
for workspace in $workspaces; do | |
cmd.attach-tmux "$workspace" | |
sleep 1 | |
done | |
} | |
function cmd.shutdown { | |
local workspace workspaces | |
workspaces="$WORKSPACES" | |
workspace="${1:-}" | |
if [[ -n "$workspace" ]]; then | |
workspaces="$workspace" | |
fi | |
for workspace in $workspaces; do | |
if tmux list-sessions 2>&1 | grep -q "$workspace:"; then | |
echo "killing workspace $workspace" | |
tmux kill-session -t "$workspace" || : | |
else | |
echo "workspace is not active: $workspace" | |
fi | |
done | |
} | |
function cmd.reset { | |
cmd.shutdown "$@" | |
sleep 1 | |
cmd.open-all "$@" | |
} | |
function cmd.sanitize-for-gist { | |
sed 's/project/project/g' < "$0" | xclip | |
sed 's/project/project/g' < "$0" | |
} | |
function cmd.show-help { | |
echo "az cmd opts" | |
echo "" | |
grep "## [a]bbr-help: " "$0" | cut -f2- -d: | |
echo "" | |
} | |
function main { | |
local cmd="${1:-}" | |
case "$cmd" in | |
all) | |
shift | |
cmd.open-all | |
sleep 1 | |
cmd.open-all-urls | |
;; | |
cypress-web) ## abbr-help: az cypress-web # d:1 cypress web testing | |
shift; cmd.attach-tmux cypress-web ;; | |
cypress-admin) ## abbr-help: az cypress-admin # d:1 cypress admin testing | |
shift; cmd.attach-tmux cypress-admin ;; | |
terraform) ## abbr-help: az terraform # d:1 terraform infra | |
shift; cmd.attach-tmux terraform ;; | |
project-web|web) ## abbr-help: az project-web|web # d:2 public website | |
shift; cmd.attach-tmux project-web ;; | |
lambda-handler|lambda) ## abbr-help: az lambda-handler|lambda # d:3 aws lambda handler, the api | |
shift; cmd.attach-tmux lambda-handler ;; | |
cider-scratchpad|cider) ## abbr-help: az cider # d:4 cider scratchpad | |
shift; cmd.attach-tmux cider-scratchpad ;; | |
project-admin|admin) ## abbr-help: az admin # d:5 admin website | |
shift; cmd.attach-tmux project-admin ;; | |
api-tests) ## abbr-help: az api-tests # d:6 clojure api integration tests | |
shift; cmd.attach-tmux api-tests ;; | |
urls) ## abbr-help: az urls # d:2 open public and admin sites in chrome | |
shift; cmd.open-all-urls ;; | |
shutdown|stop) ## abbr-help: az shutdown|stop # kill all tmux sessions | |
shift; cmd.shutdown "$@" ;; | |
reset) ## abbr-help: az reset # kill and restart all tmux sessions | |
shift; cmd.reset "$@" ;; | |
gist) ## abbr-help: az gist # sanitize for a public gist | |
cmd.sanitize-for-gist ;; | |
workspaces) ## abbr-help: az workspaces # list names of all workspaces, used by completion | |
echo "$WORKSPACES" ;; | |
commands) ## abbr-help: az commands # list names of all workspaces, used by completion | |
echo "$COMMANDS" ;; | |
*) | |
cmd.show-help ;; | |
esac | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment