dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit 2bff42a386968a9d64d55f4ff042adb1b9b20575
parent 1ae9af948322c85963dfff6a8e292ff8777bf39d
Author: hhvn <dev@hhvn.uk>
Date:   Sun,  4 Jul 2021 14:04:58 +0100

.s/b/plumb: refactor/redesign

Diffstat:
M.scripts/bin/plumb | 80++++++++++++++++++++++++++++++++++++-------------------------------------------
1 file changed, 36 insertions(+), 44 deletions(-)

diff --git a/.scripts/bin/plumb b/.scripts/bin/plumb @@ -4,18 +4,6 @@ echo(){ printf '%s\n' "$*" } -prompt(){ - prompt_var="$1" - shift - - stty >/dev/null && { - printf '%s: ' "$*" - read -r $prompt_var - } || { - prompt_var=$(</dev/null dmenu -i -p "$*") - } -} - matches(){ echo "$arg" | grep -Ei "$@" >/dev/null } @@ -24,21 +12,22 @@ fmatches(){ file "$arg" | grep -Ei "$@" >/dev/null } -rand(){ - base64 </dev/urandom | tr / + | head -c$1 -} - plumb(){ - [ "$1" = "gui" ] && { - gui=1 - shift - } + t="$1"; shift [ $norun -eq 1 ] && return export norun=1 - [ $gui -eq 1 ] && - sh -c "$*" "$arg" & - [ $gui -eq 0 ] && - ${TERMINAL:-st} sh -c "$*" "$arg" & + case "$t" in + gui) + >/dev/null nohup sh -c "$*" "$arg" & + ;; + terminal) + >/dev/null nohup ${TERMINAL:-st} sh -c "$*" "$arg" & + ;; + esac +} + +rand(){ + base64 </dev/urandom | tr / + | head -c$1 } _mktemp(){ @@ -51,41 +40,44 @@ _mktemp(){ for arg in "$@" do - herbe "arg: $arg" - norun=0 - gui=0 + export norun=0 + export gui=0 + export proxy="" # network + matches "://.*\.onion" && + export proxy="torsocks" + matches "^magnet:" && - plumb 'addtorrent $0' + plumb terminal 'addtorrent $0' matches "^(gopher|http)s?://.*\.(mkv|mp4|avi|webm|ogg|ogv|gifv|mp3|mp4|opus|flac|ape|m3u|m3u8)$" || matches "^https?://.*youtu.*be" && - plumb 'mpv --pause $0' + plumb gui '$proxy mpv --pause $0' matches "^(gopher|http)s?://.*\.(jpe?g|gif|tiff?|ppm|bit|bmp|png|xpm)$" && - plumb gui 'netimg $0' + plumb gui '$proxy netimg $0' matches "^https?://" && - plumb gui 'xprop -id $(cat /tmp/tabbed.xid) >/dev/null && surf -e $(cat /tmp/tabbed.xid) $0 || >/tmp/tabbed.xid tabbed -c surf -e $(sleep 1 && cat /tmp/tabbed.xid) $0' + plumb gui 'xprop -id $(cat /tmp/tabbed.xid) >/dev/null && $proxy surf -e $(cat /tmp/tabbed.xid) $0 || >/tmp/tabbed.xid tabbed -c $proxy surf -e $(sleep 3 && cat /tmp/tabbed.xid) $0' - matches "^gophers?://(.*/1(/|$)|[^/]*$)" && - plumb 'cgo $0' + matches "^gophers?://(.*/[17+](/|$)|[^/]*$)" && + plumb terminal '$proxy cgo $0' matches "^gophers?://" && - plumb 'curl $0 | vim -' + plumb terminal '$proxy curl $0 | vim -' matches "^mailto:" && - plumb 'neomutt $(echo "$0" | sed "s~^mailto:~~")' + plumb terminal 'neomutt $(echo "$0" | sed "s~^mailto:~~")' matches "^finger://" && - plumb 'finger $(echo "$0" | sed "s~^finger://~~")' + plumb terminal '$proxy finger $(echo "$0" | sed "s~^finger://~~")' matches "^ssh://" && - plumb 'ssh $(echo "$0" | sed "s~^ssh://~~;s~:[0-9]*~~")' + plumb terminal '$proxy ssh $(echo "$0" | sed "s~^ssh://~~;s~:[0-9]*~~")' matches "^git://" && - plumb 'git clone $0' + plumb terminal '$proxy git clone $0' # local files now matches ".*\.(epub|ps|eps|pdf|dvi|djvu)$" || @@ -94,7 +86,7 @@ do matches ".*\.(mkv|mp4|avi|webm|ogg|ogv|gifv|mp3|mp4|opus|flac|ape|m3u|m3u8)$" || fmatches "video|matroska|audio|sound" && - plumb 'mpv --pause $0' + plumb terminal 'mpv --pause $0' matches ".*\.(jpe?g|gif|tiff?|ppm|bit|bmp|png|xpm)$" || fmatches "image" && @@ -102,21 +94,21 @@ do matches ".*\.h$" && [ -f "/usr/include/$arg" ] && - plumb 'vim /usr/include/$0' + plumb terminal 'vim /usr/include/$0' matches ".*\.h$" && [ -f "/usr/local/include/$arg" ] && - plumb 'vim /usr/local/include/$0' + plumb terminal 'vim /usr/local/include/$0' matches "/.*\.[0-9]p?$" && fmatches "(roff|preprocessor)" && - plumb 'man $0' + plumb terminal 'man $0' matches "[^/].*\.[0-9]p?$" && fmatches "(roff|preprocessor)" && - plumb 'man ./$0' + plumb terminal 'man ./$0' matches ".*" && - plumb 'vim $0' + plumb terminal 'vim $0' done wait