summaryrefslogtreecommitdiff
path: root/scripts/browser
blob: 3ed94944c63c1c584eb748e34f8cc74b4a998fa1 (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
#!/usr/bin/env bash

default_browser=$(xdg-settings get default-web-browser)

if [ -z "$default_browser" ]; then
    notify-send -u normal "Default Browser" "Default browser not set."
    exit 1
fi

for path in /usr/local/share/applications /usr/share/applications ~/.local/share/applications; do
    if [ -f "$path/$default_browser" ]; then
        browser_path="$path/$default_browser"
        break
    fi
done

if [ -z "$browser_path" ]; then
    notify-send -u normal "Default Browser" "Could not find .desktop file for default browser."
    exit 1
fi

browser_command=$(grep -m 1 '^Exec=' "$browser_path" | sed 's/^Exec=//; s/ .*$//')

if [ -z "$browser_command" ]; then
    notify-send -u normal "Default Browser" "Could not extract command from .desktop file."
    exit 1
elif [ -n "$browser_command" ]; then
    $browser_command & disown
fi