dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit f0eb67b6a0082f6a3fedffac908a76199009d931
parent f5720876449c083528635b92aa8e16e941d002dc
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Sat, 22 Feb 2020 15:38:55 +0100

Use regex matching instead of case globs for identifying uri

Diffstat:
M.local/bin/plumb | 43+++++++++++++++++++++++--------------------
1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/.local/bin/plumb b/.local/bin/plumb @@ -31,6 +31,10 @@ detach() { nohup "$@" >/dev/null 2>&1 & } +regexmatch() { + printf '%s' "$1" | grep -E -q "$2" +} + fetch() { _o="$(mktemp)" if type -v hurl >/dev/null 2>&1; then @@ -81,26 +85,25 @@ handle_target() { 1="$(printf '%s' "$1" | sed 's/.*scholar_url?url\=//;s/&hl\=.*//')";; esac - case "$1" in - *.mp4|*.mkv|*.webm|*.ogv|*.avi|*.ogg|*.ogv|*.gifv) - detach mpv "$1";; - *.png|*.jpg|*.jpeg|*.tif|*.bmp|*.gif) - sxiv "$(fetch "$1")";; - *.pdf|*.ps|*.epub|*.djvu) - zathura "$(fetch "$1")";; - *youtube.com*|*youtu.be*) - cd ~/tmp && detach youtube-dl "$1";; - *smbc-comics.com*|*xkcd.com*|*jspowerhour.com*) - cd /tmp && detach comic "$1";; - 10.[0-9]*\/*) - detach $BROWSER "https://doi.org/${1}" ;; - gopher://*) - detach $TERMINAL sacc "$1";; - http://*|https://*) - detach $BROWSER "$1";; - *) - die "unknown target type: $1" - esac + if regexmatch "$1" '\.(mp4|mkv|webm|ogv|avi|ogg|ogv|gifv)$'; then + detach mpv "$1" + elif regexmatch "$1" '\.(png|jpg|jpeg|tif|bmp|gif)$'; then + sxiv "$(fetch "$1")" + elif regexmatch "$1" '\.(pdf|ps|epub|djvu)$'; then + zathura "$(fetch "$1")" + elif regexmatch "$1" '(youtube\.|youtu\.be)'; then + cd ~/tmp && detach youtube-dl "$1" + elif regexmatch "$1" '(smbc-comics\.com|xkcd\.com|jspowerhour\.com)'; then + cd /tmp && detach comic "$1" + elif regexmatch "$1" '10\.[0-9]*\/'; then + detach $BROWSER "https://doi.org/${1}" + elif regexmatch "$1" '^gopher://'; then + detach $TERMINAL sacc "$1" + elif regexmatch "$1" '^(http|https)://'; then + detach $BROWSER "$1" + else + die "unknown target type: $1" + fi fi }