dotfiles

*nix config files
git clone git://git.pyratebeard.net/dotfiles.git
Log | Files | Refs | README

commit b7e8df7a1949fe68b1d136032e48350213bc3497
parent 8c455bc4891d67c52142fe5997ef5ed4ac5a26d4
Author: pyratebeard <root@pyratebeard.net>
Date:   Fri, 25 Nov 2022 17:01:39 +0000

mailfmt scripts for mutt (thanks z3bra)

Diffstat:
Abin/bin/mailfmt | 9+++++++++
Abin/bin/mailfmtshort | 28++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/bin/bin/mailfmt b/bin/bin/mailfmt @@ -0,0 +1,9 @@ +#!/bin/sh + +w=$(tput cols) +if [ -z "$w" ] || [ "$w" -gt 120 ] ; then + w=120 +fi + +# trim mutt [-- Attachment --] headers +grep -vE -- '\[-- .* --\]$' | fmt -s -w $w diff --git a/bin/bin/mailfmtshort b/bin/bin/mailfmtshort @@ -0,0 +1,28 @@ +#!/bin/sh +# use shortner running on lxc container urlshort + +w=$(tput cols) +if [ -z "$w" ] || [ "$w" -gt 120 ] ; then + w=120 +fi + +tmp1=$(mktemp -p /tmp mailfmt.XXXXXXXX) +tmp2=$(mktemp -p /tmp mailfmt.XXXXXXXX) +trap "rm -f $tmp1 $tmp2" EXIT QUIT INT + +# trim mutt [-- Attachment --] headers +grep -vE -- '\[-- .* --\]$' | fmt -s -w $w | tee $tmp1 > $tmp2 + +grep -oE '[hH][tT]{2}[pP][sS]?://([^/?#><"]+)([^?#><"]*)(\?([^#><"]*))?(#(.*))?' $tmp1 | sort | uniq | while read url; do + if [ "$(echo $url | wc -c)" -gt $w ]; then + # shorten url + short=$(curl -sS -X PUT -d "$url" http://s.rum.sh) + + # escape special chars in url for passing it to sed + escape=$(printf '%s\n' "$url" | sed 's/[]\/$*.^[]/\\&/g') + + # replace url with short link (using space as sed separator) + sed -i "s $escape $short g" $tmp2 + fi +done +cat $tmp2