-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmux-node-dev
executable file
·59 lines (47 loc) · 1.2 KB
/
tmux-node-dev
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
#!/bin/bash
if [ "$1" == "" ]; then
echo "Please specify the directory '~/git/XYZ' of the node project"
exit 0
fi
DIR="$1"
SESSION="dev-$DIR"
DIR="$HOME/git/$DIR"
DOTFILES="$HOME/git/dotfiles"
ATTACH="tmux -2 attach -t $SESSION"
function activate-mongodb () {
MONGOSERVICE="mongodb.service"
if ! systemctl is-active "$MONGOSERVICE" &> /dev/null; then
echo "Activate mongodb service?"
read ANSWER
if [ "$ANSWER" == "y" ] || [ "$ANSWER" == "yes" ]; then
systemctl start "$MONGOSERVICE"
fi
fi
}
if tmux has-session -t "$SESSION"; then
while true; do
echo "Session already exists. Attach/kill? (a/k)"
read ANSWER
if [ "$ANSWER" == "a" ]; then
$ATTACH
exit 0
fi
if [ "$ANSWER" == "k" ]; then
tmux kill-session -t "$SESSION"
break
fi
done
fi
activate-mongodb
cd "$DIR"
tmux new-session -s "$SESSION" -n 'vim' -d
tmux send-keys -t "$SESSION:vim" 'vim -S '
tmux new-window -n 'run' -d
tmux split-window -v -t 'run' -d #'npm start; bash -i'
tmux send-keys -t "$SESSION:run.2" 'while true; do npm start; done'
tmux new-window -n 'git' -d 'git status; bash -i'
tmux split-window -h -t 'git' -c "$DOTFILES" -d 'git status; bash -i'
$ATTACH
cd -