~chambln/public-inbox

A pager that colors GMI files v1 PROPOSED

Peter Marinov
Peter Marinov: 1
 A pager that colors GMI files

 1 files changed, 35 insertions(+), 0 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~chambln/public-inbox/patches/22805/mbox | git am -3
Learn more about email & git
View this thread in the archives

[PATCH] A pager that colors GMI files Export this patch

Peter Marinov
* This uses the gawk script from folder contrib

* It can be invoked as a substitute to `less`
---
 lessgmi | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 lessgmi

diff --git a/lessgmi b/lessgmi
new file mode 100755
index 0000000..76f54df
--- /dev/null
+++ b/lessgmi
@@ -0,0 +1,35 @@
#!/bin/sh

# A wrapper around `less` that can color .gmi files

if test $(which gawk)
then
    # `gawk` is present, use it
    _AWK=gawk
    # TODO: Official install is probably /usr/share/gmi?
    _SCRIPT=contrib/gmi_color_gawk.awk
else
    # `gawk` is missing
    # TODO: fall back to plain `awk`, for the moment fall-back on plain `less`
    less $*
    exit 0
fi

# test if stdin is a tty
if test -t 0
then
    # Command example: `./lessgmi README.gmi`
    if [ -z "$1" ]
    then
        # Case of no args, invoke `less` to display the error and help
        echo "error: Missing filename"
        exit 1
    else
        # TODO: This assumes the first argument is the file, can be
        # any of the arguments
        $_AWK -f $_SCRIPT $1 | less --raw $2 $3 $4 $5 $6 $7 $8 $9
    fi
else
    # Command example: `cat README.gmi | ./lessgmi`
    $_AWK -f $_SCRIPT | less --raw $*
fi
-- 
2.25.1