plumber

Plumber – a modern approach to plumbing
git clone git://r-36.net/plumber
Log | Files | Refs | README | LICENSE

commit d86f9ba8251740a9155b56ca632c5f9733afec3b
parent 2557114b5b8017213e7aaf344dcd40576fe1c53f
Author: Christoph Lohmann <20h@r-36.net>
Date:   Wed, 12 Jul 2023 18:07:06 +0200

Add see and view command.

Diffstat:
Mbin/plumber | 2+-
Abin/see | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/view | 2++
3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/bin/plumber b/bin/plumber @@ -27,7 +27,7 @@ plumbrules = [ ["^.*://.*\.(pdf|PDF)$", "pdfopener '%s'"], ["^gopher(|s)://.*\.(txt|TXT|patch|PATCH|diff|DIFF)$", "textgopheropener '%s'"], ["^.*://.*\.(txt|TXT|patch|PATCH|diff|DIFF)$", "textwebopener '%s'"], - ["^.*://.*\.(mpg|MPG|mp3|MP3|mp4|MP4|FLAC|flac|ogg|OGG|m3u|M3U|m3u8|M3U8|flv|FLV|webm|WEBM|opus|OPUS|mov|MOV|mkv|MKV|ogv|OGV|wav|WAV)$",\ + ["^.*://.*\.(mpg|MPG|mp3|MP3|mp4|MP4|FLAC|flac|ogg|OGG|m3u|M3U|m3u8|M3U8|flv|FLV|webm|WEBM|opus|OPUS|mov|MOV|mkv|MKV|ogv|OGV|wav|WAV|avi|AVI)$",\ "mediaopener '%s'"], ["^dvb://.*", "tvopener '%s'"], ["^geo:.*", "geoopener '%s'"], diff --git a/bin/see b/bin/see @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# coding=utf-8 +# +# © 20XX Christoph Lohmann <20h@r-36.net> +# +# This file is published under the terms of the GPLv3. +# + +import os +import sys +import getopt +import mailcap +import mimetypes +import subprocess + +def usage(app): + app = os.path.basename(app) + print("usage: %s [-h] file" % (app), file=sys.stderr) + sys.exit(1) + +def main(args): + try: + opts, largs = getopt.getopt(args[1:], "h") + except getopt.GetoptError as err: + print(str(err)) + usage(args[0]) + + for o, a in opts: + if o == "-h": + usage(args[0]) + else: + assert False, "unhandled option" + + if len(largs) < 1: + usage(args[0]) + + caps = mailcap.getcaps() + (typ, enc) = mimetypes.guess_type(largs[0], strict=False) + if typ == None: + return 1 + (cmd, ent) = mailcap.findmatch(caps, typ, 'view', + largs[0]) + if cmd == None: + return 1 + + return subprocess.call(cmd, shell=True, stdin=sys.stdin) + +if __name__ == "__main__": + sys.exit(main(sys.argv)) + diff --git a/bin/view b/bin/view @@ -0,0 +1 @@ +see +\ No newline at end of file