From 6bb0ef9cc230916d7636d9eebc20b67bd3f3e394 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharchenko Date: Sun, 30 Oct 2022 20:58:35 +0200 Subject: [PATCH] linkhandler: refactor --- .local/bin/menu/linkhandler | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/.local/bin/menu/linkhandler b/.local/bin/menu/linkhandler index bfd8799..d95fbfc 100755 --- a/.local/bin/menu/linkhandler +++ b/.local/bin/menu/linkhandler @@ -1,18 +1,22 @@ #!/bin/sh -# Feed this script a link and it will give dmenu -# some choice programs to use to open it. feed="${1:-$(printf "%s" | tofi --prompt-text 'Paste URL or file path')}" -case "$(printf "yt-dlp\\nyt-dlp (audio)\\nyt-dlp (music)\\nmpv\\nmpv (audio)\\ncurl\\nzathura\\nimv\\nvim\\nbrowser" | tofi --prompt-text "Handle it with?")" in - "yt-dlp") qndl "$feed" >/dev/null 2>&1 ;; - "yt-dlp (audio)") qndl "$feed" 'yt-dlp -f bestaudio/best' >/dev/null 2>&1 ;; - "yt-dlp (music)") qndl "$feed" 'yt-dlp -f bestaudio/best -x --no-playlist --audio-format mp3 -o $XDG_MUSIC_DIR/%(title)s.%(ext)s' >/dev/null 2>&1 ;; - "mpv") setsid -f "$TERMINAL" -e mpv --quiet "$feed" >/dev/null 2>&1 ;; - "mpv (audio)") setsid -f "$TERMINAL" -e mpv --quiet --no-video "$feed" >/dev/null 2>&1 ;; - "curl") qndl "$feed" 'curl -LO' >/dev/null 2>&1 ;; - zathura) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && setsid -f zathura "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; - imv) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && setsid -f imv "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; - vim) curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && setsid -f "$TERMINAL" -e "$EDITOR" "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; - browser) setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 +case "$feed" in + *mkv|*webm|*mp4|*youtube.com*|*youtu.be*|*yewtu.be*|*videos.lukesmith.xyz*|*spacepub.space*|*twitch.tv*) + case "$(printf "yt-dlp\\nyt-dlp (audio)\\nyt-dlp (music)\\nmpv\\nmpv (audio)" | tofi --prompt-text "Handle media with?")" in + "yt-dlp") qndl "$feed" >/dev/null 2>&1 ;; + "yt-dlp (audio)") qndl "$feed" 'yt-dlp -f bestaudio/best' >/dev/null 2>&1 ;; + "yt-dlp (music)") qndl "$feed" 'yt-dlp -f bestaudio/best -x --no-playlist --audio-format mp3 -o $XDG_MUSIC_DIR/%(title)s.%(ext)s' >/dev/null 2>&1 ;; + "mpv") setsid -f "$TERMINAL" -e mpv --quiet "$feed" >/dev/null 2>&1 ;; + "mpv (audio)") setsid -f "$TERMINAL" -e mpv --quiet --no-video "$feed" >/dev/null 2>&1 ;; + esac ;; + *png|*jpg|*jpe|*jpeg|*gif) + curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && setsid -f imv "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; + *pdf|*cbz|*cbr) + curl -sL "$feed" > "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" && setsid -f zathura "/tmp/$(echo "$feed" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 ;; + *go.dev*|*lukesmith.xyz*|*drewdevault.com*) + setsid -f foot elinks "$feed" ;; + *) + setsid -f "$BROWSER" "$feed" >/dev/null 2>&1 esac