aboutsummaryrefslogtreecommitdiff
path: root/tmux/tmux-npmStart.sh
blob: 00326e2a813eda87ca1531a8377c9238258460a6 (plain)
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
#!/bin/sh

# tmux-npmStart.sh: Run 'npm start' on a new tmux window
#
# Usage: tmux-npmStart.sh [-r]

usageMessage="Usage: ${0} [-r]"

error() {
	printf '%s error: %s\n' "$0" "$*" >&2
}

errorAndUsage() {
	printf '%s error: %s\n%s\n' "$0" "$*" "$usageMessage" >&2
}

window=9
name='npm start'
remainOnExit=''

# Process options
while getopts ':r' opt; do
	case $opt in

		'r' )
			remainOnExit='y'
			;;

		'?' )
			printf '%s\n' "$usageMessage" >&2
			exit 1

	esac
done
shift $((OPTIND - 1))

if tmux list-windows | grep -q "^${window}: ${name}"; then
	tmux kill-window -t "$window"
else
	if [ -z "$remainOnExit" ]; then
		tmux new-window -db -t "$window" -n "$name" 'npm start'
	else
		tmux new-window -b -t "$window" -n "$name" 'tmux set -w remain-on-exit on; npm start'
	fi
fi