aboutsummaryrefslogtreecommitdiff
path: root/misc/.local/bin/dmenu_urlhandler
blob: e73d7d36355e72987bbe1e9d6d9452bf538faa72 (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
48
49
50
51
52
53
54
55
56
#!/bin/bash

# Ideas:
#   - Open video
#   - Open audio
#   - Add to bookmarks

URL_PATTERN='^(https?://)?([A-Za-z0-9-]+\.)+[A-Za-z0-9-]+(:[0-9]+)?(/.*)?'
URL=$(xclip -out -selection clipboard 2>/dev/null | tr -d '\n')
[[ "$URL" =~ $URL_PATTERN ]] || exit 0

# Actions
#NOTE="🗒 note           $URL"
READER="🤓 reader-mode    $URL"
SANITISE="✨ sanitise       $URL"
UNSHORTEN="🔄 unshorten      $URL"
UNSHORTEN_WEB="🔄 unshorten-web  $URL"
WEBARCHIVE_SEARCH="🔍 search         $URL"
WEBARCHIVE_SAVE="💾 save           $URL"

ACTION=$(echo -e "$READER\n$SANITISE\n$UNSHORTEN\n$UNSHORTEN_WEB\n$WEBARCHIVE_SEARCH\n$WEBARCHIVE_SAVE" | dmenu -l 6 -h 23 -p "Action:")
[ -z "$ACTION" ] && exit 0

PREFIX=""
case $ACTION in
    # *note*)
    #     $TERMINAL -e joyce new --url "$URL"
    #     exit 0
    #     ;;
    *reader-mode*)
        READ=$(mktemp --suffix=.html)
        readable --output "$READ" "$URL"
        surf "$READ"
        exit 0
        ;;
    *sanitise*)
        URL="https://search.dyamon.me/sanitise/post?mortyurl=$URL"
        ;;
    *unshorten\ *)
        #URL=$(curl -sIL "$URL" | sed -n 's/[Ll]ocation: *//p' | tail -n1 | tr -d '\n')
        URL=$(curl -sSL -D - "$URL" -o /dev/null | sed -n 's/[Ll]ocation: *//p' | tail -n1 | tr -d '\n')
        ;;
    *unshorten-web*)
        URL="https://unshorten.me/s/$URL"
        URL=$(curl -s "$URL" | tr -d '\n')
        ;;
    *search*)
        URL="https://web.archive.org/web/*/$URL"
        ;;
    *save*)
        URL="https://web.archive.org/save/$URL"
        ;;
esac

echo "$URL" | xclip -in -selection clipboard
dmenu_omnibar $@