diff options
| author | EuAndreh <eu@euandre.org> | 2022-05-04 20:01:13 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2022-05-04 20:01:15 -0300 |
| commit | 06ddff4c7041922f70595d836b17f2eb983d3046 (patch) | |
| tree | 366a93215a89e396a0919e7475e855bde0acf6fd | |
| parent | ~/.local/bin/xmpp: Do not default TO_JID to eu@euandreh.xyz (diff) | |
| download | dotfiles-06ddff4c7041922f70595d836b17f2eb983d3046.tar.gz dotfiles-06ddff4c7041922f70595d836b17f2eb983d3046.tar.xz | |
~/.local/bin/email: Add working script!
I'm on a streak!
| -rwxr-xr-x | .local/bin/email | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/.local/bin/email b/.local/bin/email new file mode 100755 index 00000000..0a1fd159 --- /dev/null +++ b/.local/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 "$@" |
