THEAARBS menus - dmenuhandler

Published 04-29-2018 09:17:26

Raw

#!/bin/bash
# Feed this script a URL and choose what opens it
# Bound to Mod+y
MenuChoices=\
"$READER
$IMGVIEWER
$BROWSER
w3m
mpv
mpv (loop)
mpv (float)
wget
stream-dl
bandcamp-dl"
runprefix=
mymenu=$(setmenu -l)
amitty=$(tty)
case $amitty in
    *tty1|"not a tty") runprefix="$TERMINAL -e" ;;
esac
if [ -z $1 ] ; then url=$(inprompt "URL:") || exit
else url=$1 ; fi
handle_url() {
    if [[ "${#1}" -gt 30 ]]
    then visual="${1:0:20}"..."${1: -7}"
    else visual="$1"
    fi
    echo $visual
    choice=$(echo -e "$MenuChoices" | $mymenu "Handler for $visual:")
    clear
    case "$choice" in
        "$READER")    $runprefix $READER "$1" &disown ;;
        "IMGVIEWER")  $IMGVIEWER "$1" &disown ;;
        "$BROWSER")   $BROWSER "$1" & disown ;;
        w3m)        $runprefix w3m "$1" ;;
        mpv)        mpv -quiet "$1" & disown ;;
        "mpv (loop)") mpv -quiet --loop "$1" & disown ;;
        "mpv (float)")    mpv --geometry=+0-0 --autofit=30%  --title="mpvfloat" /dev/video0 "$1" & disown ;;
        wget)       wget "$1" & disown ;;
        stream-dl)  youtube-dl "$1" & disown ;;
        bandcamp-dl)    cd ~/Downloads
                bandcamp-dl "$1" >/dev/null &&
                notify-send "👍 Finished downloading" "$(basename $1)" ||
                notify-send "⛔ Error downloading" "$(basename $1)" ;;
    esac ;}

handle_url $url