Initial commit - plumb - Open certain URL patterns with an ad-hoc opener (plumber) (HTM) hg clone https://bitbucket.org/iamleot/plumb (DIR) Log (DIR) Files (DIR) Refs (DIR) README --- (DIR) changeset 51858d13cfbcd1966bfe15978aafecbe95f0355d (HTM) Author: Leonardo Taccari <iamleot@gmail.com> Date: Sat, 24 Mar 2018 16:02:52 Initial commit Diffstat: dplumb | 53 +++++++++++++++++++++++ openers/arxiv | 7 +++ openers/dilbert | 8 +++ openers/gopher | 5 ++ openers/image | 10 ++++ openers/media | 5 ++ openers/pdf | 10 ++++ openers/txt | 5 ++ openers/txtweb | 5 ++ openers/web | 5 ++ plumb | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 238 insertions(+), 0 deletions(-) --- diff -r 000000000000 -r 51858d13cfbc dplumb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dplumb Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,53 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Leonardo Taccari +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + + +: ${PLUMB_DMENU:=dmenu -l 10} + +plumb "$( +awk \ +' +BEGIN { + FS = RS = "[ \t\n]+" +} + +/:\/\// { + # Get rid of possible delimiters (<...>, (...), [...]) + if (match($0, /\<[0-9A-Za-z]+:\/\/[^>]+\>/) || + match($0, /\([0-9A-Za-z]+:\/\/[^)]+\)/) || + match($0, /\[[0-9A-Za-z]+:\/\/[^]]+\]/)) { + print substr($0, RSTART + 1, RLENGTH - 2) + } else { + print $0 + } +} +' | +${PLUMB_DMENU} )" + +exit 0 diff -r 000000000000 -r 51858d13cfbc openers/arxiv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/arxiv Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,7 @@ +#!/bin/sh + +for u in "$@"; do + id="$(printf "%s\n" "$u" | cut -d : -f 2)" + pdfurl="https://arxiv.org/pdf/${id}.pdf" + plumb "${pdfurl}" +done diff -r 000000000000 -r 51858d13cfbc openers/dilbert --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/dilbert Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,8 @@ +#!/bin/sh + +for u in "$@"; do + gifurl=$(curl -s -L "$u" | + xmllint --html --xpath '//meta[@property="og:image"]/@content' - 2>/dev/null | + sed -e 's/^ content="//' -e 's/"$/.gif/') + plumb "${gifurl}" +done diff -r 000000000000 -r 51858d13cfbc openers/gopher --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/gopher Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,5 @@ +#!/bin/sh + +for u in "$@"; do + tmux new-window "sacc \"$u\"" +done diff -r 000000000000 -r 51858d13cfbc openers/image --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/image Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,10 @@ +#!/bin/sh + +mkdir -p ${XDG_CACHE_HOME:-~/.cache}/imagecache +cd ${XDG_CACHE_HOME:-~/.cache}/imagecache + +for u in "$@"; do + f="$(basename "$u")" + curl -s --user-agent "Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0" -Lz "$f" -O "$u" + open "$f" +done diff -r 000000000000 -r 51858d13cfbc openers/media --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/media Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,5 @@ +#!/bin/sh + +for u in "$@"; do + tmux new-window "mpv \"$u\"" +done diff -r 000000000000 -r 51858d13cfbc openers/pdf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/pdf Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,10 @@ +#!/bin/sh + +mkdir -p ${XDG_CACHE_HOME:-~/.cache}/pdfcache +cd ${XDG_CACHE_HOME:-~/.cache}/pdfcache + +for u in "$@"; do + f="$(basename "$u")" + curl -s --user-agent "Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0" -Lz "$f" -O "$u" + open "$f" +done diff -r 000000000000 -r 51858d13cfbc openers/txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/txt Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,5 @@ +#!/bin/sh + +for u in "$@"; do + tmux new-window "w3m \"$u\"" +done diff -r 000000000000 -r 51858d13cfbc openers/txtweb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/txtweb Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,5 @@ +#!/bin/sh + +for u in "$@"; do + tmux new-window "w3m \"$u\"" +done diff -r 000000000000 -r 51858d13cfbc openers/web --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/openers/web Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,5 @@ +#!/bin/sh + +for u in "$@"; do + www-browser "$u" +done diff -r 000000000000 -r 51858d13cfbc plumb --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plumb Sat Mar 24 16:02:52 2018 +0100 @@ -0,0 +1,125 @@ +#!/bin/sh + +# +# Copyright (c) 2018 Leonardo Taccari +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + + +: ${PLUMB_OPENERS_PATH:=${HOME}/.plumb/openers} +: ${PLUMB_NOOPEN:=no} + + +# +# Print usage information and exit. +# +usage() +{ + echo "usage: $0 [-n] [url ...]" + + exit 1 +} + + +# +# Launch the requested opener given an URL. +# +open() +{ + opener="$1" + url="$2" + + if [ "${PLUMB_NOOPEN}" = "yes" ]; then + echo "${opener} \"${url}\"" + else + ${PLUMB_OPENERS_PATH}/${opener} "${url}" + fi +} + + +main() +{ + + while getopts n f; do + case $f in + n) PLUMB_NOOPEN="yes";; + ?) usage;; + esac + done + shift $((OPTIND - 1)) + + + for u in "$@"; do + case $u in + *://*.pdf ) + open "pdf" "$u" + ;; + *://*.txt | *://*.patch | *://*.diff | *://*.log ) + open "txt" "$u" + ;; + *://*.jpg | *://*.jpeg | *://*.png | *://*.gif ) + open "image" "$u" + ;; + *://*.mp3 | *://*.ogg | *://*.m3u8 | *://*.opus | *://*.flac | \ + *://*.mp4 | *://*.webm | *://*.gifv | \ + *://youtu.be/* | *://www.youtube.com/* | *://youtube.com/* | \ + ytdl://* ) + open "media" "$u" + ;; + gopher://* ) + open "gopher" "$u" + ;; + http://feed.dilbert.com/*/[0-9]*-[0-9]*-[0-9]* | \ + http://dilbert.com/strip/[0-9]*-[0-9]*-[0-9]* ) + open "dilbert" "$u" + ;; + *://codepad.org/* | *://paste.* | *://pastebin.* | \ + *://sprunge.us/* | *://slexy.org/* | *://ix.io/* ) + open "txtweb" "$u" + ;; + *://mail-index.netbsd.org/* | *://mail-index.NetBSD.org/* | \ + *://www.mail-archive.info/* | *://lkml.org/* | \ + *://marc.info/* | *://www.openwall.com/lists/* ) + open "txtweb" "$u" + ;; + *://gnats.netbsd.org/* | *://gnats.NetBSD.org/* ) + open "txtweb" "$u" + ;; + *://*/meta/report.html ) + open "txtweb" "$u" + ;; + http://* | https://* ) + open "web" "$u" + ;; + arxiv://* ) + open "arxiv" "$u" + ;; + esac + done + +} + + +main "$@"