dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 395e32791cdc76e6c3ca5dadc6c67947324f921e
parent 45b388165e10ed9f017ae3f2d3c3722cd47aff2b
Author: Alex Balgavy <alex@balgavy.eu>
Date:   Sun, 24 Apr 2022 17:46:19 +0200

Attempt to unify the way links are handled

I basically want to have a menu pop up with possible actions. I want it
to work with fzf on mac, and dmenu on linux, depending on the CHOOSER
variable. Also it should work with a plumbing keybinding. This is the
first step, the system will be improved in later commits.

Diffstat:
Mnewsboat/config | 6------
Dscripts/bcdl | 21---------------------
Ascripts/fzfchoose | 2++
Mscripts/linkhandler | 80+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
Dscripts/newsboat-dl | 26--------------------------
Mscripts/opener | 2+-
Mshell/env | 2+-
7 files changed, 80 insertions(+), 59 deletions(-)

diff --git a/newsboat/config b/newsboat/config @@ -57,13 +57,7 @@ browser "linkhandler %u" unbind-key , bind-key SPACE macro-prefix macro SPACE set browser "open -g %u"; open-in-browser; set browser "linkhandler %u" -- "Open in browser" -macro v set browser "linkhandler"; open-in-browser ; set browser "linkhandler %u" -- "Open with linkhandler" -macro a set browser "mpc add \"$(youtube-dl -x -g %u)\" && mpc play"; open-in-browser; set browser "linkhandler %u" -- "Play as audio" -macro w set browser "w3m -config ~/.config/w3m/config %u"; open-in-browser; set browser "linkhandler %u" -- "Open in w3m" macro i set browser "youtube-dl --get-title --get-duration --get-description %u | less"; open-in-browser; set browser "linkhandler %u" -- "Get media info" macro c set browser "printf '%s' %u | clc" ; open-in-browser ; set browser "linkhandler %u" -- "Copy link" macro u set browser "urlview"; open-in-browser ; set browser "linkhandler %u" -- "Urlview" -macro l set browser "notify 'Downloading' %u 'bcdl' && setsid -f bcdl %u >/tmp/bcdl$(date +%s).log 2>&1"; open-in-browser; set browser "linkhandler %u" -- "Bandcamp download" macro s set browser "pocket save %u && notify 'Saved to Pocket' %u 'pocket' || notify 'Could not save' %u 'pocket'"; open-in-browser ; set browser "linkhandler %u" -- "Save to Pocket" -macro d set browser "newsboat-dl av %u 1>/dev/null 2>&1 & disown"; open-in-browser ; set browser "linkhandler %u" -- "Download video" -macro n set browser "newsboat-dl aonly %u 1>/dev/null 2>&1 & disown"; open-in-browser ; set browser "linkhandler %u" -- "Download audio only" diff --git a/scripts/bcdl b/scripts/bcdl @@ -1,21 +0,0 @@ -#!/bin/sh -# Wrapper for youtube-dl, configured specifically for Bandcamp -# $1 is the URL - -DOWNLOAD_DIR="$HOME"/Downloads/songs/listen\ to -cd "$DOWNLOAD_DIR" || { printf "Couldn't cd into download directory %s\n" "$DOWNLOAD_DIR"; exit 1; } -command -v youtube-dl 1>/dev/null 2>&1 || { printf "Youtube-dl required.\n"; exit 1; } -[ $# -eq 1 ] || { printf "One argument required: album url\n"; exit 1; } - -url="$1" -name="${url##*/}" -artist="$(printf "%s" "$url" | sed 's|https*://||;s:\.bandcamp\.com.*::')" - -[ -d "$artist" ] || mkdir -p "$artist" -cd "$artist" || { printf "Couldn't cd into directory %s\n" "$(pwd)/$artist"; exit 1; } -[ -d "$name" ] || mkdir -p "$name" -cd "$name" || { printf "Couldn't cd into directory %s\n" "$(pwd)/$name"; exit 1; } -youtube-dl -f mp3 -o "%(playlist_index)s %(title)s %(id)s.%(ext)s" "$url" -printf "#EXTM3U\n#PLAYLIST:%s\n#EXTART:%s\n" "$name" "$artist" > "$name".m3u -youtube-dl -f mp3 --get-filename -o "%(playlist_index)s %(title)s %(id)s.%(ext)s" "$url" >> "$name".m3u -notify "Downloaded $artist - $name" "$url" bcdl diff --git a/scripts/fzfchoose b/scripts/fzfchoose @@ -0,0 +1,2 @@ +#!/bin/sh +fzf-tmux --prompt="Choose > " --layout=reverse diff --git a/scripts/linkhandler b/scripts/linkhandler @@ -1,9 +1,75 @@ #!/bin/sh # Linkhandler: handles links. Like `opener` but for URLs case "$1" in + *bandcamp.com*) + case "$(printf 'Download\nPlay' | "$CHOOSER")" in + Download) + DOWNLOAD_DIR="$HOME"/Downloads/songs/listen\ to + mkdir -p "$DOWNLOAD_DIR" + cd "$DOWNLOAD_DIR" || { printf "Couldn't cd into download directory %s\n" "$DOWNLOAD_DIR"; exit 1; } + command -v youtube-dl 1>/dev/null 2>&1 || { printf "Youtube-dl required.\n"; exit 1; } + + url="$1" + name="${url##*/}" + artist="$(printf "%s" "$url" | sed 's|https*://||;s:\.bandcamp\.com.*::')" + + [ -d "$artist" ] || mkdir -p "$artist" + cd "$artist" || { printf "Couldn't cd into directory %s\n" "$(pwd)/$artist"; exit 1; } + [ -d "$name" ] || mkdir -p "$name" + cd "$name" || { printf "Couldn't cd into directory %s\n" "$(pwd)/$name"; exit 1; } + youtube-dl -f mp3 -o "%(playlist_index)s %(title)s %(id)s.%(ext)s" "$url" + printf "#EXTM3U\n#PLAYLIST:%s\n#EXTART:%s\n" "$name" "$artist" > "$name".m3u + youtube-dl -f mp3 --get-filename -o "%(playlist_index)s %(title)s %(id)s.%(ext)s" --exec "notify 'Downloaded $artist - $name' '$url' bcdl" "$url" >> "$name".m3u + ;; + Play) + case "$(printf 'Audio (queue in mpd)\nAudio (mpv)' | "$CHOOSER")" in + 'Audio (queue in mpd)') + mpc add "$(youtube-dl -x -g "$1")" + ;; + 'Audio (mpv)') + mpv --no-audio-display --no-video --volume=50 "$1" + ;; + esac + ;; + esac + ;; *mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*|*videos.lukesmith.xyz*|*v.redd.it*|*fb.watch*) - notify 'Starting mpv' "Opening $1..." 'linkhandler' - setsid -f mpvq "$1" 1>/dev/null 2>&1 + case "$(printf 'Open\nDownload\nPlay' | "$CHOOSER")" in + Open) + open "$1" + ;; + Download) + DOWNLOAD_DIR=~/Downloads/ + case "$(printf 'Both\nAudio\nVideo' | "$CHOOSER")" in + Both) + notify 'Download (av) started' "Downloading" linkhandler + nohup >/dev/null youtube-dl --add-metadata -ic --write-sub --embed-subs -o "$DOWNLOAD_DIR/%(title)s-%(creator)s.%(ext)s" --exec "notify 'Download finished' 'Downloaded.' linkhandler" "$1" & disown + ;; + Audio) + notify 'Download (audio) started' "Downloading" linkhandler + nohup >/dev/null youtube-dl --add-metadata -xic -f bestaudio/best -o "$DOWNLOAD_DIR/%(title)s-%(creator)s.%(ext)s" --exec "notify 'Download finished' 'Downloaded.' linkhandler" "$1" & disown + ;; + Video) + notify 'Download (video) started' "Downloading" 'linkhandler' + nohup >/dev/null youtube-dl -f bestvideo --add-metadata -ic --write-sub --embed-subs -o "$DOWNLOAD_DIR/%(title)s-%(creator)s.%(ext)s" --exec "notify 'Download finished' 'Downloaded.' linkhandler" "$1" & disown + ;; + esac + ;; + Play) + case "$(printf 'Video\nAudio (queue in mpd)\nAudio (mpv)' | "$CHOOSER")" in + Video) + setsid -f mpvq "$1" 1>/dev/null 2>&1 + notify 'Starting mpv' "Opening $1..." 'linkhandler' + ;; + 'Audio (queue in mpd)') + mpc add "$(youtube-dl -x -g "$1")" + ;; + 'Audio (mpv)') + mpv --no-audio-display --no-video --volume=50 "$1" + ;; + esac + ;; + esac ;; *png|*jpg|*jpe|*jpeg|*gif) notify 'Starting image viewer' "Opening $1..." 'linkhandler' @@ -14,7 +80,13 @@ case "$1" in setsid -f mpv -loop "$1" 1>/dev/null 2>&1 ;; *mp3|*flac|*opus|*mp3?source*) - setsid -f mpv --volume=50 "$1" 1>/dev/null 2>&1 + case "$(printf 'Download\nPlay' | "$CHOOSER")" in + Download) + ;; + Play) + setsid -f mpv --volume=50 "$1" 1>/dev/null 2>&1 + ;; + esac ;; *reddit.com*) reddio print -c always "comments/$(printf "%s" "$1" | cut -d/ -f7)" | less -+F -+X @@ -44,7 +116,7 @@ case "$1" in esac ;; '@http'*) - printf "${1##@}" | clc + printf '%s' "${1##@}" | clc ;; *) if [ -f "$1" ]; then "${EDITOR:-vim}" "$1" diff --git a/scripts/newsboat-dl b/scripts/newsboat-dl @@ -1,26 +0,0 @@ -#!/bin/sh -# Download audio/video from newsboat. This script generally isn't executed manually, but via newsboat macros. -[ $# -eq 2 ] || { terminal-notifier -title "Not enough arguments" -message "Need exactly 2 arguments." && exit 1; } -what="$1" -where="$2" -downloads="$HOME/Downloads/" -audiodir="$downloads/newsboat/audio" -videodir="$downloads/newsboat/video" -logfile="$HOME/.cache/newsboat-download.log" -title=$(youtube-dl --ignore-config --get-title --get-duration --get-description "$where" 2>/dev/null) - -terminal-notifier -title "Started $what download" -message "Downloading \"$title\"" -group "$where" -case "$what" in - "aonly") - mkdir -p "$audiodir" - youtube-dl --add-metadata -xic -f bestaudio/best -o "$audiodir/%(title)s-%(creator)s.%(ext)s" "$where" >>"$logfile" 2>&1 - ;; - "av") - youtube-dl --add-metadata -ic --write-sub --embed-subs -o "$videodir/%(title)s-%(creator)s.%(ext)s" "$where" >>"$logfile" 2>&1 - ;; - *) - terminal-notifier -title "Error" -message "Download option not valid" -group "$where" - exit 1 - ;; -esac -terminal-notifier -title "Download complete" -message "Downloaded \"$title\"" -group "$where" diff --git a/scripts/opener b/scripts/opener @@ -3,7 +3,7 @@ [ $# -gt 0 ] || { printf "File required in argument.\n" && exit 1; } case "$1" in # Handling links is another script's job - http*) linkhandler "$@";; + *://*) linkhandler "$@";; *) case $(file --mime-type "$1" -bL) in text/*|application/json|inode/x-empty) { [ -n "$VIM_TERMINAL" ] && vimsend "$1"; } || ${EDITOR:-vim} "$1";; diff --git a/shell/env b/shell/env @@ -8,8 +8,8 @@ elif [ -n "$INSIDE_EMACS" ]; then EDITOR="emacsclient" else EDITOR="$(command -v vim)"; fi export EDITOR +export CHOOSER=fzfchoose export MUSIC_DIR="/Volumes/HDD/Music/Libraries/Mine" - export PAGER="less" export LESS="-FRiX"