aboutsummaryrefslogtreecommitdiff
path: root/bin/msg
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-05-18 03:45:55 -0300
committerEuAndreh <eu@euandre.org>2022-05-18 03:45:55 -0300
commit6252a67b158103ed601a981296bc23e1526f1703 (patch)
treede4fbb5d628a7b86745a0754669f528b71806897 /bin/msg
parentetc/guix/current: Add guix profile symlink (diff)
downloaddotfiles-6252a67b158103ed601a981296bc23e1526f1703.tar.gz
dotfiles-6252a67b158103ed601a981296bc23e1526f1703.tar.xz
bin/msg: Use a single MESSAGE for all actions that take an argument
Diffstat (limited to 'bin/msg')
-rwxr-xr-xbin/msg73
1 files changed, 58 insertions, 15 deletions
diff --git a/bin/msg b/bin/msg
index 32f4fd9..137c62c 100755
--- a/bin/msg
+++ b/bin/msg
@@ -4,7 +4,7 @@ set -eu
usage() {
cat <<-'EOF'
Usage:
- msg -X XMPP_MESSAGE -s -S SOUND_MESSAGE -m EMAIL -D DESKTOP -b
+ msg [-X|-s|-S|-m|-D|-b] [MESSAGE]
msg -h
EOF
}
@@ -13,12 +13,12 @@ help() {
cat <<-'EOF'
Options:
- -X XMPP_MESSAGE send XMPP using the `xmpp` command
- -s play $XDG_DATA_HOME/msg/medium.ogg sound
- -S SOUND_MESSAGE say SOUND_MESSAGE using `speak`
- -m EMAIL_SUBJECT send email with EMAIL_SUBJECT and empty body
- -D DESKTOP_MESSAGE the desktop message for `notify-send`
- -b print terminal bell
+ -X send MESSAGE using the `xmpp` command
+ -s play $XDG_DATA_HOME/msg/medium.ogg sound
+ -S say MESSAGE using `speak`
+ -m send email with MESSAGE as subject and empty body
+ -D send desktop MESSAGE via `notify-send`
+ -b print terminal bell
-h, --help show this message
EOF
}
@@ -39,34 +39,41 @@ for flag in "$@"; do
done
sound() {
- play $XDG_DATA_HOME/msg/medium.ogg 2>/dev/null
+ play "$XDG_DATA_HOME"/msg/medium.ogg 2>/dev/null
}
+XMPP=false
+SOUND=false
+SPEAK=false
+MAIL=false
+DESKTOP=false
+BELL=false
ACTION_DONE=false
-while getopts 'X:sS:m:D:bh' flag; do
+SHOW_USAGE=false
+while getopts 'XsSmDbh' flag; do
case "$flag" in
X)
- xmpp -m "$OPTARG" eu@euandreh.xyz &
+ XMPP=true
ACTION_DONE=true
;;
s)
- sound &
+ SOUND=true
ACTION_DONE=true
;;
S)
- echo "$OPTARG" | speak -v pt-BR &
+ SPEAK=true
ACTION_DONE=true
;;
m)
- echo " " | email -s "$OPTARG" eu@euandre.org &
+ MAIL=true
ACTION_DONE=true
;;
D)
- notify-send "$OPTARG" &
+ DESKTOP=true
ACTION_DONE=true
;;
b)
- printf '\a' &
+ BELL=true
ACTION_DONE=true
;;
h)
@@ -80,11 +87,47 @@ while getopts 'X:sS:m:D:bh' flag; do
;;
esac
done
+shift $((OPTIND - 1))
if [ "$ACTION_DONE" = false ]; then
sound
usage
help
+ exit
+fi
+
+
+MESSAGE="${1:-}"
+
+assert_arg() {
+ if [ -z "$1" ]; then
+ printf 'Missing %s.\n\n' "$2" >&2
+ usage >&2
+ exit 2
+ fi
+}
+
+if [ "$XMPP" = true ]; then
+ assert_arg "$MESSAGE" '-X MESSAGE'
+ xmpp -m "$MESSAGE" eu@euandreh.xyz &
+fi
+if [ "$SOUND" = true ]; then
+ sound &
+fi
+if [ "$SPEAK" = true ]; then
+ assert_arg "$MESSAGE" '-S MESSAGE'
+ echo "$MESSAGE" | speak -v pt-BR &
+fi
+if [ "$MAIL" = true ]; then
+ assert_arg "$MESSAGE" '-m MESSAGE'
+ echo " " | email -s "$MESSAGE" eu@euandre.org &
+fi
+if [ "$DESKTOP" = true ]; then
+ assert_arg "$MESSAGE" '-D MESSAGE'
+ notify-send "$MESSAGE" &
+fi
+if [ "$BELL" = true ]; then
+ printf '\a' &
fi
wait