summaryrefslogtreecommitdiff
path: root/.local/bin/desktop/librewolf-open
blob: fd97234cd84f7f5e69b0d66d48f76574cd421ee3 (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
#!/bin/sh

window="LibreWolf"
running() { windows=$(wmctrl -l)
	test "${windows#*"$window"}" != "$windows"; }
press() { sleep 0.1; xdotool keyup Super
	xdotool key --clearmodifiers "$@"; }

if ! running; then
	notify-send "Starting $window..."
	start="$(date +%s.%3N)"
	setsid -f librewolf -P "${FFPROFILE:-default-release}"
	for _ in $(seq 1000); do sleep 0.1; running && break; done
	end="$(date +%s.%3N)"
	time="$(echo "$end - $start" | bc)"
	notify-send "$window" "Started in ${time}s"
	started=1
fi

wmctrl -a "$window" ||
	{ notify-send "ffbrowser" "ERROR: librewolf window not found"; exit 1; }
[ "$started" = 1 ] || press ctrl+t

query="$*"
if [ "$query" != "${query#http*://}" ]; then
	press ctrl+l
elif [ -e "$query" ]; then
	query="$(readlink -f "$query")"; press ctrl+l
else
	# workaround for ctrl+k not working at initial startup
	[ "$started" = 1 ] && return
	press ctrl+k
fi

if [ -n "$query" ]; then
	xdotool type "$query"
	press Return
fi