From e598c486e317b563fb502ebc7352f71cdc003ffd Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Thu, 12 May 2022 10:31:44 -0300 Subject: git mv .local/bin/ .usr/bin/ --- .usr/bin/email | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 .usr/bin/email (limited to '.usr/bin/email') diff --git a/.usr/bin/email b/.usr/bin/email new file mode 100755 index 00000000..0a1fd159 --- /dev/null +++ b/.usr/bin/email @@ -0,0 +1,74 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + mail -s SUBJECT ADDRESS... < BODY + mail -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -s SUBJECT the email subject + -h, --help show this message + + ADDRESS the email addresses to send the email to + BODY the text to be sent as the body + EOF +} + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +while getopts 's:h' flag; do + case "$flag" in + s) + SUBJECT="$OPTARG" + ;; + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +assert_arg() { + if [ -z "$1" ]; then + { + printf 'Missing %s.\n' "$2" + printf '\n' + usage + } >&2 + exit 2 + fi +} + +assert_arg "${SUBJECT:-}" '-s SUBJECT' +assert_arg "${1:-}" 'ADDRESS' + +printf 'Subject: %s\n\n%s' \ + "$(echo "$SUBJECT" | tr -d '\n')" \ + "$(cat)" | + msmtpq -a euandreh "$@" -- cgit v1.3