aboutsummaryrefslogtreecommitdiffstats
path: root/surf-open.sh
blob: fc559eb8382dbe981e3e94059621cbc6a3035bb4 (plain) (blame)
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
#!/bin/sh
#
# See the LICENSE file for copyright and license details.
#
# Point a running surf at a URI, or start a new one if none is running.
# Every surf window leaves a control fifo named <pid>-<pageid> behind, see
# the CONTROL FIFO section of surf(1).

uri="${1:-about:blank}"

for fifo in "${XDG_RUNTIME_DIR:-/tmp}"/surf/*; do
	[ -p "$fifo" ] || continue

	# a fifo of a surf that got killed would block us forever
	pid="${fifo##*/}"
	if ! kill -0 "${pid%%-*}" 2>/dev/null; then
		rm -f "$fifo"
		continue
	fi

	printf 'uri %s\n' "$uri" >"$fifo"
	exit 0
done

exec surf "$uri"