aboutsummaryrefslogtreecommitdiff
path: root/bin/email
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-05-12 12:01:54 -0300
committerEuAndreh <eu@euandre.org>2022-05-12 12:01:54 -0300
commit90eaebabcaaea74237f34cf05709625345f276cc (patch)
tree349e7609d20ecfb6567652a7e28595cec9647eb0 /bin/email
parent.usr/etc/i3/config: WIP setup extra bindings (diff)
downloaddotfiles-90eaebabcaaea74237f34cf05709625345f276cc.tar.gz
dotfiles-90eaebabcaaea74237f34cf05709625345f276cc.tar.xz
Move Git repository into ~/.usr/.git/
Diffstat (limited to 'bin/email')
-rwxr-xr-xbin/email74
1 files changed, 74 insertions, 0 deletions
diff --git a/bin/email b/bin/email
new file mode 100755
index 0000000..0a1fd15
--- /dev/null
+++ b/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 "$@"