diff options
author | EuAndreh <eu@euandre.org> | 2023-02-17 15:07:30 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2023-02-17 15:07:32 -0300 |
commit | 44b1e103b4d3a24aee89587ef302891e9f9c3807 (patch) | |
tree | a8e4045218bd1075b687dd5a6f1d023e6c407bff | |
parent | etc/nix/configuration.nix: Add flutter2 and hover packages (diff) | |
download | dotfiles-44b1e103b4d3a24aee89587ef302891e9f9c3807.tar.gz dotfiles-44b1e103b4d3a24aee89587ef302891e9f9c3807.tar.xz |
bin/: Use explicit "--" separator for assert-arg usages
In order to prevent legitimate cases to fail as errors, such as:
NUM='-10'
eval "$(assert-arg "$NUM" '-n NUM')"
To prevent assert-arg(1) from treating "-10" as the options "-1 and -0,
they need to be put after the "--" separator.
This way, all usages of assert-arg(1) that had its first argument as a
variable were adapted, and the usage and examples of assert-arg itself
were updated to encourage this best practice.
-rwxr-xr-x | bin/assert-arg | 4 | ||||
-rwxr-xr-x | bin/clamp | 6 | ||||
-rwxr-xr-x | bin/color | 4 | ||||
-rwxr-xr-x | bin/email | 4 | ||||
-rwxr-xr-x | bin/forever | 2 | ||||
-rwxr-xr-x | bin/grun | 4 | ||||
-rwxr-xr-x | bin/lines | 2 | ||||
-rwxr-xr-x | bin/menu | 2 | ||||
-rwxr-xr-x | bin/msg | 8 | ||||
-rwxr-xr-x | bin/n-times | 2 | ||||
-rwxr-xr-x | bin/ootb | 2 | ||||
-rwxr-xr-x | bin/player | 2 | ||||
-rwxr-xr-x | bin/playlist | 2 | ||||
-rwxr-xr-x | bin/pre | 2 | ||||
-rwxr-xr-x | bin/prompt | 2 | ||||
-rwxr-xr-x | bin/rfc | 2 | ||||
-rwxr-xr-x | bin/vcs | 2 | ||||
-rwxr-xr-x | bin/vm | 6 | ||||
-rwxr-xr-x | bin/volume | 2 | ||||
-rwxr-xr-x | bin/with-email | 2 | ||||
-rwxr-xr-x | bin/without-env | 4 | ||||
-rwxr-xr-x | bin/wms | 2 |
22 files changed, 34 insertions, 34 deletions
diff --git a/bin/assert-arg b/bin/assert-arg index d7bc8f4..3c8990a 100755 --- a/bin/assert-arg +++ b/bin/assert-arg @@ -4,7 +4,7 @@ set -eu usage() { cat <<-'EOF' Usage: - assert-arg STRING MESSAGE + assert-arg -- STRING MESSAGE assert-arg -h EOF } @@ -23,7 +23,7 @@ help() { Assert that $1 contains an argument, named FILENAME: - $ eval "$(assert-arg "${1:-}" 'FILENAME')" + $ eval "$(assert-arg -- "${1:-}" 'FILENAME')" EOF } @@ -73,9 +73,9 @@ NUMBER="${1:-}" MIN="${2:-}" MAX="${3:-}" -eval "$(assert-arg "$NUMBER" 'NUMBER')" -eval "$(assert-arg "$MIN" 'MIN')" -eval "$(assert-arg "$MAX" 'MAX')" +eval "$(assert-arg -- "$NUMBER" 'NUMBER')" +eval "$(assert-arg -- "$MIN" 'MIN')" +eval "$(assert-arg -- "$MAX" 'MAX')" if [ "$MIN" -gt "$MAX" ]; then @@ -208,8 +208,8 @@ shift $((OPTIND - 1)) TEXT="${1:-}" -eval "$(assert-arg "$COLOR_FN" '-c COLOR')" -eval "$(assert-arg "$TEXT" 'TEXT')" +eval "$(assert-arg -- "$COLOR_FN" '-c COLOR')" +eval "$(assert-arg -- "$TEXT" 'TEXT')" "$COLOR_FN" "$TEXT" @@ -72,8 +72,8 @@ shift $((OPTIND - 1)) ADDRESS="${1:-}" -eval "$(assert-arg "${SUBJECT:-}" '-s SUBJECT')" -eval "$(assert-arg "$ADDRESS" 'ADDRESS')" +eval "$(assert-arg -- "${SUBJECT:-}" '-s SUBJECT')" +eval "$(assert-arg -- "$ADDRESS" 'ADDRESS')" { cat <<-EOF diff --git a/bin/forever b/bin/forever index d4410e5..1ecc2a8 100755 --- a/bin/forever +++ b/bin/forever @@ -58,7 +58,7 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -eval "$(assert-arg "${1:-}" 'COMMAND')" +eval "$(assert-arg -- "${1:-}" 'COMMAND')" while true; do @@ -72,7 +72,7 @@ done shift $((OPTIND - 1)) FILENAME="${1:-}" -eval "$(assert-arg "$FILENAME" 'FILENAME')" +eval "$(assert-arg -- "$FILENAME" 'FILENAME')" shift if [ "${1:-}" != '--' ]; then @@ -82,7 +82,7 @@ if [ "${1:-}" != '--' ]; then fi shift -eval "$(assert-arg "${1:-}" 'COMMAND')" +eval "$(assert-arg -- "${1:-}" 'COMMAND')" if [ ! -e "$FILENAME" ]; then @@ -76,6 +76,6 @@ else END=$(($2 - START + 1)) fi -eval "$(assert-arg "$START" 'START')" +eval "$(assert-arg -- "$START" 'START')" tail -n +"$START" | head -n "$END" @@ -72,7 +72,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" DATA() { @@ -124,22 +124,22 @@ fi MESSAGE="${1:-}" if [ "$XMPP" = true ]; then - eval "$(assert-arg "$MESSAGE" '-X MESSAGE')" + eval "$(assert-arg -- "$MESSAGE" '-X MESSAGE')" xmpp -m "$MESSAGE" eu@euandre.org & fi if [ "$SOUND" = true ]; then sound & fi if [ "$SPEAK" = true ]; then - eval "$(assert-arg "$MESSAGE" '-S MESSAGE')" + eval "$(assert-arg -- "$MESSAGE" '-S MESSAGE')" echo "$MESSAGE" | speak -v pt-BR & fi if [ "$MAIL" = true ]; then - eval "$(assert-arg "$MESSAGE" '-m MESSAGE')" + eval "$(assert-arg -- "$MESSAGE" '-m MESSAGE')" echo " " | email -s "$MESSAGE" eu@euandre.org & fi if [ "$DESKTOP" = true ]; then - eval "$(assert-arg "$MESSAGE" '-D MESSAGE')" + eval "$(assert-arg -- "$MESSAGE" '-D MESSAGE')" if [ "$OK" = true ]; then notify-send -t 5000 "$MESSAGE" & else diff --git a/bin/n-times b/bin/n-times index 4fa8b96..c8d10d8 100755 --- a/bin/n-times +++ b/bin/n-times @@ -61,7 +61,7 @@ shift $((OPTIND - 1)) COUNT="${1:-}" shift -eval "$(assert-arg "$COUNT" 'COUNT')" +eval "$(assert-arg -- "$COUNT" 'COUNT')" while true; do @@ -93,7 +93,7 @@ shift $((OPTIND - 1)) BUILD_DIRECTORY="${1:-}" -eval "$(assert-arg "$BUILD_DIRECTORY" 'BUILD_DIRECTORY')" +eval "$(assert-arg -- "$BUILD_DIRECTORY" 'BUILD_DIRECTORY')" mkdir -p "$BUILD_DIRECTORY" @@ -73,7 +73,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" diff --git a/bin/playlist b/bin/playlist index bd01d23..8b9271f 100755 --- a/bin/playlist +++ b/bin/playlist @@ -67,7 +67,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" F="$XDG_DATA_HOME"/euandreh/playlist.txt @@ -67,7 +67,7 @@ done shift $((OPTIND - 1)) PREFIX="${1:-}" -eval "$(assert-arg "$PREFIX" 'PREFIX')" +eval "$(assert-arg -- "$PREFIX" 'PREFIX')" while read -r line; do if [ -z "$COLOR" ]; then @@ -64,7 +64,7 @@ done shift $((OPTIND - 1)) STRING="${1:-}" -eval "$(assert-arg "$STRING" 'STRING')" +eval "$(assert-arg -- "$STRING" 'STRING')" printf '%s' "$STRING" printf ' [Y/n]: ' @@ -133,7 +133,7 @@ if [ "${UPDATE:-}" = true ]; then exit fi -eval "$(assert-arg "$RFC_NUMBER" 'RFC_NUMBER')" +eval "$(assert-arg -- "$RFC_NUMBER" 'RFC_NUMBER')" if [ ! -e "$F" ]; then printf 'Given RFC_NUMBER "%s" does not exist at:\n%s\n' \ @@ -232,7 +232,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" shift if [ "${1:-}" = '--' ]; then @@ -214,7 +214,7 @@ write_ssh_config ACTION="${1:-}" OS="${2:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" shift @@ -247,7 +247,7 @@ case "$ACTION" in done ;; up) - eval "$(assert-arg "$OS" 'OS')" + eval "$(assert-arg -- "$OS" 'OS')" shift if [ "${1:-}" = '--' ]; then shift @@ -301,7 +301,7 @@ case "$ACTION" in write_ssh_config ;; down) - eval "$(assert-arg "$OS" 'OS')" + eval "$(assert-arg -- "$OS" 'OS')" shift if [ "${1:-}" = '--' ]; then shift @@ -74,7 +74,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" rotate() { diff --git a/bin/with-email b/bin/with-email index 7df101a..bd3ef96 100755 --- a/bin/with-email +++ b/bin/with-email @@ -69,7 +69,7 @@ while getopts 's:h' flag; do done shift $((OPTIND - 1)) -eval "$(assert-arg "${1:-}" 'COMMAND...')" +eval "$(assert-arg -- "${1:-}" 'COMMAND...')" now() { date '+%Y-%m-%dT%H:%M:%S%Z' diff --git a/bin/without-env b/bin/without-env index fd9d1e8..57c2d2e 100755 --- a/bin/without-env +++ b/bin/without-env @@ -57,8 +57,8 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -eval "$(assert-arg "${1:-}" 'ENVVAR')" -eval "$(assert-arg "${2:-}" 'PATH')" +eval "$(assert-arg -- "${1:-}" 'ENVVAR')" +eval "$(assert-arg -- "${2:-}" 'PATH')" eval "export $1=\"\$(echo \"\$$1\" | sed \"s|\$2:||g\")\"" shift # drop $1 @@ -67,7 +67,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" copy_and_notify() { |