-
Notifications
You must be signed in to change notification settings - Fork 2
/
browser
executable file
·62 lines (56 loc) · 1.46 KB
/
browser
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
57
58
59
60
61
62
#!/bin/bash
#set -o xtrace
USERBR=""
RUNNING=false
BROWSERS=( nightly aurora firefox chrome chromium chromium-browser qupzilla opera )
CMDS=()
# gather all process which could match
for BR in ${BROWSERS[*]}; do
CMD=$(ps -C "$BR" -o user,cmd | grep "^$USER");
CMDS+=($CMD)
done
# find the first matching (== obey the users priority)
for BR in ${BROWSERS[*]}; do
for CMD in ${CMDS[*]}; do
grep -q "$BR" <<<$CMD && USERBR=$BR && break;
done
[[ ! -z "$USERBR" ]] && break
done
if [[ -z "$USERBR" ]]; then
USERBR=${BROWSERS[0]}
for BR in ${BROWSERS[*]}; do
if which "$BR" &> /dev/null; then
USERBR=$BR
break
fi
done
else
RUNNING=true
fi
if which "$USERBR" &> /dev/null; then
## for debugging:
#notify-send -a 'browser' \
# -i 'internet-web-browser' \
# -c 'error' \
# 'Browser launched!' \
# "Browser ${USERBR} '$@' launched."
## -----
if [[ "$DESKTOP_SESSION" = "i3" ]]; then
if ! $RUNNING || [[ ! -z "$*" ]]; then
# not running or url/args provided
"$USERBR" "$@" &
if ! $RUNNING; then
sleep 1.3
fi
fi
i3-msg "[title=(?i)$USERBR] focus"
else
exec "$USERBR" "$@"
fi
else
notify-send -a 'browser' \
-i 'internet-web-browser' \
-c 'error' \
'Browser not found!' \
"Browser autodetection failed. (choice would be: $USERBR)"
fi