diff --git a/commands.beta/eval-on-empty-stdin b/commands.beta/eval-on-empty-stdin deleted file mode 100755 index 87de52bee..000000000 --- a/commands.beta/eval-on-empty-stdin +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -function eval_on_empty_stdin() ( - source "$DOROTHY/sources/bash.bash" - - setup-util-moreutils --quiet # ifne - - ifne -n "$@" -) - -# fire if invoked standalone -if [[ $0 == "${BASH_SOURCE[0]}" ]]; then - eval_on_empty_stdin "$@" -fi diff --git a/commands.beta/eval-on-not-empty-stdin b/commands.beta/eval-on-not-empty-stdin deleted file mode 100755 index a9cd86b59..000000000 --- a/commands.beta/eval-on-not-empty-stdin +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -function eval_on_not_empty_stdin() ( - source "$DOROTHY/sources/bash.bash" - - setup-util-moreutils --quiet # ifne - - ifne "$@" -) - -# fire if invoked standalone -if [[ $0 == "${BASH_SOURCE[0]}" ]]; then - eval_on_not_empty_stdin "$@" -fi diff --git a/commands/eval-on-empty-stdin b/commands/eval-on-empty-stdin new file mode 100755 index 000000000..c93e8f847 --- /dev/null +++ b/commands/eval-on-empty-stdin @@ -0,0 +1,71 @@ +#!/usr/bin/env bash + +function eval_on_empty_stdin() ( + source "$DOROTHY/sources/bash.bash" + + # ===================================== + # Arguments + + function help { + cat <<-EOF >/dev/stderr + ABOUT: + Execute the if stdin is empty; stdin content will continue to be directed to stdout. + Companion to [eval-on-not-empty-stdin]. + + USAGE: + eval-on-empty-stdin [--] ... + EOF + if [[ $# -ne 0 ]]; then + echo-error "$@" + fi + return 22 # EINVAL 22 Invalid argument + } + + # process + local item option_cmd=() + while [[ $# -ne 0 ]]; do + item="$1" + shift + case "$item" in + '--help' | '-h') help ;; + '--') + option_cmd+=("$@") + shift $# + break + ;; + '--'*) help "An unrecognised flag was provided: $item" ;; + *) + option_cmd+=("$item" "$@") + shift $# + break + ;; + esac + done + + # ===================================== + # Action + + # doesn't work: + # if read -r; then + # __print_lines 'not empty' + # else + # __print_lines 'empty' + # fi + + # doesn't work: + # if [[ -t 0 ]]; then + # __print_lines 'empty' + # else + # __print_lines 'not empty' + # fi + + # works: + setup-util-moreutils --quiet # ifne + ifne -n "${option_cmd[@]}" + return +) + +# fire if invoked standalone +if [[ $0 == "${BASH_SOURCE[0]}" ]]; then + eval_on_empty_stdin "$@" +fi diff --git a/commands/eval-on-not-empty-stdin b/commands/eval-on-not-empty-stdin new file mode 100755 index 000000000..2852fe99d --- /dev/null +++ b/commands/eval-on-not-empty-stdin @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +function eval_on_not_empty_stdin() ( + source "$DOROTHY/sources/bash.bash" + + # ===================================== + # Arguments + + function help { + cat <<-EOF >/dev/stderr + ABOUT: + Execute the if stdin is not empty; the stdin content will still be available to whatever eventually reads it. + Companion to [eval-on-empty-stdin]. + + USAGE: + eval-on-not-empty-stdin [--] ... + EOF + if [[ $# -ne 0 ]]; then + echo-error "$@" + fi + return 22 # EINVAL 22 Invalid argument + } + + # process + local item option_cmd=() + while [[ $# -ne 0 ]]; do + item="$1" + shift + case "$item" in + '--help' | '-h') help ;; + '--') + option_cmd+=("$@") + shift $# + break + ;; + '--'*) help "An unrecognised flag was provided: $item" ;; + *) + option_cmd+=("$item" "$@") + shift $# + break + ;; + esac + done + + # ===================================== + # Action + + setup-util-moreutils --quiet # ifne + ifne "${option_cmd[@]}" +) + +# fire if invoked standalone +if [[ $0 == "${BASH_SOURCE[0]}" ]]; then + eval_on_not_empty_stdin "$@" +fi