diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/email | 15 | ||||
-rwxr-xr-x | bin/grun | 12 | ||||
-rwxr-xr-x | bin/msg | 16 | ||||
-rwxr-xr-x | bin/pre | 10 | ||||
-rwxr-xr-x | bin/prompt | 10 | ||||
-rwxr-xr-x | bin/rfc | 10 | ||||
-rwxr-xr-x | bin/without-env | 13 |
7 files changed, 14 insertions, 72 deletions
@@ -64,19 +64,8 @@ while getopts 's:h' flag; do 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' +eval "$(assert-arg "${SUBJECT:-}" '-s SUBJECT')" +eval "$(assert-arg "${1:-}" 'ADDRESS')" printf 'Subject: %s\n\n%s' \ "$(echo "$SUBJECT" | tr -d '\n')" \ @@ -71,16 +71,8 @@ while getopts 'rh' flag; do done shift $((OPTIND - 1)) -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - FILENAME="${1:-}" -assert_arg "$FILENAME" 'FILENAME' +eval "$(assert-arg "$FILENAME" 'FILENAME')" shift if [ "${1:-}" != '--' ]; then @@ -90,7 +82,7 @@ if [ "${1:-}" != '--' ]; then fi shift -assert_arg "${1:-}" 'COMMAND' +eval "$(assert-arg "${1:-}" 'COMMAND')" if [ ! -e "$FILENAME" ]; then @@ -124,31 +124,23 @@ 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' + eval "$(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' + eval "$(assert-arg "$MESSAGE" '-S MESSAGE')" echo "$MESSAGE" | speak -v pt-BR & fi if [ "$MAIL" = true ]; then - assert_arg "$MESSAGE" '-m MESSAGE' + eval "$(assert-arg "$MESSAGE" '-m MESSAGE')" echo " " | email -s "$MESSAGE" eu@euandre.org & fi if [ "$DESKTOP" = true ]; then - assert_arg "$MESSAGE" '-D MESSAGE' + eval "$(assert-arg "$MESSAGE" '-D MESSAGE')" if [ "$OK" = true ]; then notify-send -t 5000 "$MESSAGE" & else @@ -52,16 +52,8 @@ while getopts 'c:h' flag; do done shift $((OPTIND - 1)) -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - PREFIX="${1:-}" -assert_arg "$PREFIX" 'PREFIX' +eval "$(assert-arg "$PREFIX" 'PREFIX')" while read -r line; do if [ -z "$COLOR" ]; then @@ -23,14 +23,6 @@ help() { EOF } -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s.\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - for flag in "$@"; do case "$flag" in @@ -63,7 +55,7 @@ done shift $((OPTIND - 1)) STRING="${1:-}" -assert_arg "$STRING" 'STRING' +eval "$(assert-arg "$STRING" 'STRING')" printf '%s' "$STRING" printf ' [Y/n]: ' @@ -86,14 +86,6 @@ check_local_db() { fi } -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s.\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - for flag in "$@"; do case "$flag" in @@ -141,7 +133,7 @@ if [ "${UPDATE:-}" = true ]; then exit fi -assert_arg "$RFC_NUMBER" +eval "$(assert-arg "$RFC_NUMBER")" if [ ! -e "$F" ]; then printf 'Given RFC_NUMBER "%s" does not exist at:\n%s\n' \ diff --git a/bin/without-env b/bin/without-env index 45c41ca..4f8fb14 100755 --- a/bin/without-env +++ b/bin/without-env @@ -57,16 +57,9 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s\n' "$2" >&2 - exit 2 - fi -} - -assert_arg "${1:-}" 'ENVVAR' -assert_arg "${2:-}" 'PATH' -assert_arg "${3:-}" '--' +eval "$(assert-arg "${1:-}" 'ENVVAR')" +eval "$(assert-arg "${2:-}" 'PATH')" +eval "$(assert-arg "${3:-}" '--')" eval "export $1=\"\$(echo \"\$$1\" | sed \"s|\$2:||g\")\"" shift # drop $1 |