aboutsummaryrefslogtreecommitdiff
path: root/env/.local/bin/scripts/urlview.sh
blob: 394ac66c36280f0f5cd20ee50fbe97b22d46c4eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh

url="$(grep -Eo "https?://[^]})\"'' ]*" <&0 | fzf)" # extra ' because my editor dont syntax highlight correctly
[ ! "$url" ] && exit

choices="\
clipboard
browser/xdg-open"

choice=$(echo "$choices" | fzf)
[ ! "$choice" ] && exit
choice=$(echo "$choice" | sed -e 's/browser\/xdg-open/xdg-open/') # browser/xdg-open should just run xdg-open

if [ "$choice" = "clipboard" ]; then
    if [ -z "$WAYLAND_DISPLAY" ]; then
        printf -- "%s" "$url" | xclip -selection clipboard
    else
        printf -- "%s" "$url" | wl-copy
    fi
else
	$choice "$url" & disown
fi