-
Notifications
You must be signed in to change notification settings - Fork 5
/
tmux.sh
executable file
·70 lines (62 loc) · 1.76 KB
/
tmux.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
source $DIR/.env
session="$APPNAME"
function ti() {
#tmux -d "$@" -s $session
tmux new-session -d -s $session
}
function t() {
tmux "$@"
}
function ts() {
tmux "$@" -t "$session"
}
function tsk() {
wn="$1"
shift
t send-keys -t "$session:$wn" "$@" C-m
}
function tnw() {
t new-window -a -t "$session" -n "$1"
}
function tsw() {
wn="$1"
shift
t split-window "$@" -t "$session:$wn"
}
function destroy() {
echo '* destroying previous session' && \
ts kill-session -t "$session"
}
function create() {
echo '* creating session' && \
ti && \
echo '* creating window postgrest' && \
t rename-window -t "$session.0" "postgrest" && \
tsk postgrest 'source .env ; export DBURI ; export POSTGRESTPORT ; export JWTSECRET ; [[ ! -z "$POSTGRESTPORT" ]] && postgrest postgrest.conf || echo "no POSTGRESTPORT provided"' && \
echo '* app' && \
tnw app && \
tsk app "nvm use && cd app ; npm run dev -- --port=$APP_PORT" && \
echo '* server' && \
tnw server && \
tsk server "nvm use && cd server ; PORT=$SERVER_PORT npm run start" && \
echo '* email-worker' && \
tnw email-worker && \
tsk email-worker "cli/email_worker.js -l" && \
( [[ ! -z $POSTGREST_PROXY_PORT ]] && (
echo '* postgrest_proxy' && \
tnw pgproxy && \
tsk pgproxy "source .env && mitmdump -p $POSTGREST_PROXY_PORT -w mitm.log --mode reverse:$(echo $POSTGREST_BASE_URI | sed -E 's/\/default\/testicle//g')"
) || echo '* postgrest proxy disabled')
}
function attach() {
ts attach-ses
}
echo "0 = '$0'"
[[ $0 =~ bash$ ]] && echo "tmux.sh sourced" ||
{
destroy
create && \
attach
}