Recently Written · git

prompt-mail

Ask mail-related questions and filter mail-related files with dmenu

git clone https://github.com/equwal/prompt-mail

Log | Files | Refs


commit 55d6ab9013c7469924cd05c2a24d66aa413a19ac
Spenser Truex <truex@equwal.com>
2021-01-07 11:42:40 -0800

POSIX compliant and audited

Used shellcheck and dash to check for posix compliance, was previously
full of bashisms.

 example/git-send-email |  8 ++------
 example/mail-alias     | 24 +++++++++++++-----------
 prompt-mail            |  3 +--
 3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/example/git-send-email b/example/git-send-email
index 41ed6a6..921aa5f 100755
--- a/example/git-send-email
+++ b/example/git-send-email
@@ -1,9 +1,5 @@
 #!/bin/sh
 
-# ${PARAMETER:-WORD} expands WORD if PARAMETER is null or unset.
-PROJECT=${1:-$(find . -maxdepth 1 -mindepth 1 -type d -printf "%p\n" \ # name only
-    | sed -E s:^\.[/]:: \ # No prefix
-    | xargs echo $(pwd | sed 's:^.*/::' \ # working dir
-    | dmenu -ip "Project name:"))}
-EMAIL=${2:-$(prompt-email)}
+[ -z "$1" ] && EMAIL="$(prompt-mail)"
+
 git send-email --subject-prefix="${PWD##*/}][PATCH" --to "$EMAIL" -1
diff --git a/example/mail-alias b/example/mail-alias
index d6b2b0d..b227a30 100755
--- a/example/mail-alias
+++ b/example/mail-alias
@@ -1,17 +1,19 @@
 #!/bin/sh
-CONFIG=~/.config/neomutt/aliases
+
+# Helper program for neomutt!
+# configure ~/.config/prompt-mail.conf to contain just the path to the
+# aliases filie and optional comments.
+
+
+CONFIG="$(sed '/^#.*$/d' ~/.config/prompt-mail.conf | sed -E 's/^alias // ; s/#.*$//')"
+
 add_email () {
     out=$(sed -ne 's/^From:[ \t]*//p' /dev/stdin)
     # Ensure adding aliases is idempotent with respect to mail address.
-    grep -q -F -- $(echo "$out" | sed 's/^.*<// ; s/>.*$>//') ${CONFIG}
+    grep -q -F -- $(echo "$out" | sed 's/^.*<// ; s/>.*$>//') "$CONFIG"
     active=$?
-    [ $active != 0 ] && y-or-n "Add $out? " && echo "alias $(dmenu -p 'Alias shorthand? ') $out" >> ${CONFIG}
+    [ $active != 0 ] && y-or-n "Add $out? " && echo "alias $(dmenu -p 'Alias shorthand? ') $out" >> "$CONFIG"
 }
-query () {
-cat ~/.config/prompt-mail.conf \
-    | sed 's/^#.*$//' \
-    | xargs sed -E 's/^alias // ; s/#.*$//' \
-    | grep "$1"
-}
-[ "$1" == "--add-email" ] &&  add_email </dev/stdin
-[ "$1" == "--query" ] && query "$2"
+
+[ "$1" = "--add-email" ] || [ "$1" = "-a" ] &&  add_email </dev/stdin
+[ "$1" = "--query" ] || [ "$1" = "-q" ] && grep "$2" "$CONFIG"
diff --git a/prompt-mail b/prompt-mail
index 1ac8f2a..d3c2f74 100755
--- a/prompt-mail
+++ b/prompt-mail
@@ -9,8 +9,7 @@ verify_email () {
 }
 
 mail_addrs () {
-    cat ~/.config/prompt-mail.conf  \
-        | sed 's/^#.*$//' \
+    sed 's/^#.*$//' ~/.config/prompt-mail.conf \
         | xargs sed -E 's/^alias +[a-zA-Z0-9]+ // ; s/#.*$//'
 }