From f3b91d75d2d3153e9fa4d7414929dcc531779727 Mon Sep 17 00:00:00 2001
From: Ben Sima <ben@bsima.me>
Date: Tue, 27 Aug 2019 14:34:49 -0700
Subject: reorganize, and some small fixes

---
 lib/mutt/generate-contacts.sh | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100755 lib/mutt/generate-contacts.sh

(limited to 'lib/mutt/generate-contacts.sh')

diff --git a/lib/mutt/generate-contacts.sh b/lib/mutt/generate-contacts.sh
new file mode 100755
index 0000000..ab3cacb
--- /dev/null
+++ b/lib/mutt/generate-contacts.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env sh
+#
+# Source: http://wcm1.web.rice.edu/mutt-tips.html
+
+MESSAGE=$(cat)
+
+NEWALIAS=$(echo "${MESSAGE}" | grep ^"From: " | sed s/[\,\"\']//g | awk '{$1=""; if (NF == 3) {print "alias" $0;} else if (NF == 2) {print "alias" $0 $0;} else if (NF > 3) {print "alias", tolower($(NF-1))"-"tolower($2) $0;}}')
+
+if grep -Fxq "$NEWALIAS" $HOME/contacts.txt; then
+    :
+else
+    echo "$NEWALIAS" >> $HOME/contacts.txt
+fi
+
+echo "${MESSAGE}"
-- 
cgit v1.2.3