aboutsummaryrefslogtreecommitdiff
path: root/bin/xgo
blob: 8329c5110166b083de6857e6a5256f950bf3f308 (plain) (blame)
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
#!/bin/sh
# Test and open a clipboard URL with an apt program

# Check arguments
if [ "$#" -eq 0 ] ; then
    printf 2>&1 'xgo: At least one URL required\n'
fi

# Iterate over the URL arguments
for url ; do (

    # If it's a YouTube video without a given start time, load it in mpv(1)
    case $url in
        *[/.]youtube.com/watch*[?\&]t=) ;;
        *[/.]youtube.com/watch*)
            mpv -- "$url" && exit
            ;;
        https://github.com/*/blob/*)
            url=$(printf '%s\n' "$url" | sed 's_/blob/_/raw/_')
            ;;
        *://imgur.com/*)
            url=$(printf '%s\n' "$url" | sed 's_imgur\.com_i.imgur.com_;s/$/.jpg/')
            ;;
    esac

    # Get the MIME type data
    mt=$(urlmt "$url")

    # If the MIME type is an image, load it in feh(1)
    case $mt in
        audio/*|video/*)
            mpv --force-window -- "$url" && exit
            ;;
        image/gif) ;;
        image/*)
            curl -- "$url" | feh - && exit
            ;;
        text/plain)
            # shellcheck disable=SC2016
            urxvt -e sh -c 'curl -- "$1" | view -' \
                _ "$url" && exit
            ;;
    esac

    # Otherwise, just pass it to br(1)
    br "$url"
) & done