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 8b5a4140edd947c378f8e0153980cbd392744ac9
parent ce2b0064a054a3efa464b3ceb56fbade1838bfe1
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon, 24 Feb 2020 09:31:56 +0100

Fix target preprocessing during plumbing

Diffstat:
M.local/bin/plumb | 59++++++++++++++++++++++++++++++-----------------------------
1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/.local/bin/plumb b/.local/bin/plumb @@ -49,30 +49,31 @@ fetch() { handle_target() { - if [ -e "$1" ]; then - mime_type="$(file -ib "$1")" + t="$1" + if [ -e "$t" ]; then + mime_type="$(file -ib "$t")" case "$mime_type" in image/*) - detach sxiv "$1";; + detach sxiv "$t";; video/*|audio/*) - mpv "$1";; + mpv "$t";; text/html) - detach $BROWSER "$1";; + detach $BROWSER "$t";; text/*) - $EDITOR "$1";; + $EDITOR "$t";; *shellscript*) - $EDITOR "$1";; + $EDITOR "$t";; application/*html*) - detach $BROWSER "$1";; + detach $BROWSER "$t";; application/pdf*) - detach zathura "$1";; + detach zathura "$t";; application/*document*|\ application/msword*|\ application/*-excel*|\ application/*powerpoint*|\ application/octet-stream|\ application/zip) - detach libreoffice "$1";; + detach libreoffice "$t";; *) die "file type $mime_type is not supported" esac @@ -80,29 +81,29 @@ handle_target() { else - case "$1" in + case "$t" in *scholar.google.*) - 1="$(printf '%s' "$1" | sed 's/.*scholar_url?url\=//;s/&hl\=.*//')";; + t="$(printf '%s' "$t" | sed 's/.*scholar_url?url\=//;s/&hl\=.*//')";; 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" + if regexmatch "$t" '\.(mp4|mkv|webm|ogv|avi|ogg|ogv|gifv)$'; then + detach mpv "$t" + elif regexmatch "$t" '\.(png|jpg|jpeg|tif|bmp|gif)$'; then + sxiv "$(fetch "$t")" + elif regexmatch "$t" '\.(pdf|ps|epub|djvu)$'; then + zathura "$(fetch "$t")" + elif regexmatch "$t" '(youtube\.|youtu\.be)'; then + cd ~/tmp && detach youtube-dl "$t" + elif regexmatch "$t" '(smbc-comics\.com|xkcd\.com|jspowerhour\.com)'; then + cd /tmp && detach comic "$t" + elif regexmatch "$t" '10\.[0-9]*\/'; then + detach $BROWSER "https://doi.org/${t}" + elif regexmatch "$t" '^gopher://'; then + detach $TERMINAL sacc "$t" + elif regexmatch "$t" '^(http|https)://'; then + detach $BROWSER "$t" else - die "unknown target type: $1" + die "unknown target type: $t" fi fi }