aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsurf-open.sh41
1 files changed, 17 insertions, 24 deletions
diff --git a/surf-open.sh b/surf-open.sh
index c22edc2..fc559eb 100755
--- a/surf-open.sh
+++ b/surf-open.sh
@@ -1,32 +1,25 @@
#!/bin/sh
#
-# See the LICENSE file for copyright and license details.
+# 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).
-xidfile="$HOME/tmp/tabbed-surf.xid"
-uri=""
+uri="${1:-about:blank}"
-if [ "$#" -gt 0 ];
-then
- uri="$1"
-fi
+for fifo in "${XDG_RUNTIME_DIR:-/tmp}"/surf/*; do
+ [ -p "$fifo" ] || continue
-runtabbed() {
- tabbed -dn tabbed-surf -r 2 surf -e '' "$uri" >"$xidfile" \
- 2>/dev/null &
-}
-
-if [ ! -r "$xidfile" ];
-then
- runtabbed
-else
- xid=$(cat "$xidfile")
- xprop -id "$xid" >/dev/null 2>&1
- if [ $? -gt 0 ];
- then
- runtabbed
- else
- surf -e "$xid" "$uri" >/dev/null 2>&1 &
+ # 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
-fi
+ printf 'uri %s\n' "$uri" >"$fifo"
+ exit 0
+done
+
+exec surf "$uri"