diff --git a/.editorconfig b/.editorconfig old mode 100755 new mode 100644 diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/dorothy-workflow.yml b/.github/workflows/dorothy-workflow.yml old mode 100755 new mode 100644 diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 diff --git a/.trunk/configs/.markdownlint.yaml b/.trunk/configs/.markdownlint.yaml old mode 100755 new mode 100644 diff --git a/.trunk/configs/.prettierrc.yaml b/.trunk/configs/.prettierrc.yaml old mode 100755 new mode 100644 diff --git a/.trunk/configs/.shellcheckrc b/.trunk/configs/.shellcheckrc old mode 100755 new mode 100644 diff --git a/.trunk/configs/.yamllint.yaml b/.trunk/configs/.yamllint.yaml old mode 100755 new mode 100644 diff --git a/.trunk/configs/eslint.config.js b/.trunk/configs/eslint.config.js old mode 100755 new mode 100644 diff --git a/.trunk/configs/ruff.toml b/.trunk/configs/ruff.toml old mode 100755 new mode 100644 diff --git a/.trunk/trunk.yaml b/.trunk/trunk.yaml old mode 100755 new mode 100644 index af018b9b0..9c8bd795c --- a/.trunk/trunk.yaml +++ b/.trunk/trunk.yaml @@ -22,19 +22,19 @@ lint: enabled: - actionlint@1.6.26 - black@23.12.1 - - checkov@3.1.57 + - checkov@3.1.69 - eslint@8.56.0 - flake8@7.0.0 - git-diff-check@SYSTEM - gitleaks@8.18.1 - isort@5.13.2 - markdownlint@0.38.0 - - prettier@3.1.1 - - ruff@0.1.12 + - prettier@3.2.4 + - ruff@0.1.14 - shellcheck@0.9.0 - shfmt@3.7.0 - taplo@0.8.1 - - trufflehog@3.63.8 + - trufflehog@3.63.11 - yamllint@1.33.0 disabled: - trivy diff --git a/.vscode/extensions.json b/.vscode/extensions.json old mode 100755 new mode 100644 diff --git a/.vscode/settings.json b/.vscode/settings.json old mode 100755 new mode 100644 diff --git a/.vscode/workspace.code-workspace b/.vscode/workspace.code-workspace old mode 100755 new mode 100644 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md old mode 100755 new mode 100644 diff --git a/LICENSE.md b/LICENSE.md old mode 100755 new mode 100644 diff --git a/README.md b/README.md old mode 100755 new mode 100644 index 27f9be2fa..a7c837011 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ + Dorothy is a dotfile ecosystem featuring: - seamless support for [Bash](), [Zsh](https://en.wikipedia.org/wiki/Z_shell), [Fish](), [Nu](https://www.nushell.sh), [Xonsh](https://xon.sh), [Elvish](https://elv.sh), [Dash](https://wiki.archlinux.org/title/Dash), [KSH](https://en.wikipedia.org/wiki/KornShell) @@ -277,12 +278,12 @@ Join the [Bevry Software community](https://discord.gg/nQuXddV7VP) to stay up-to #### Contributors -- [Benjamin Lupton](https://github.com/balupton) — [view contributions](https://github.com/bevry/dorothy/commits?author=balupton 'View the GitHub contributions of Benjamin Lupton on repository bevry/dorothy') -- [Bevry Team](https://github.com/BevryMe) — [view contributions](https://github.com/bevry/dorothy/commits?author=BevryMe 'View the GitHub contributions of Bevry Team on repository bevry/dorothy') -- [BJReplay](https://github.com/BJReplay) — [view contributions](https://github.com/bevry/dorothy/commits?author=BJReplay 'View the GitHub contributions of BJReplay on repository bevry/dorothy') -- [molleweide](https://github.com/molleweide) — [view contributions](https://github.com/bevry/dorothy/commits?author=molleweide 'View the GitHub contributions of molleweide on repository bevry/dorothy') -- [Nutchanon Ninyawee](https://github.com/wasdee) — [view contributions](https://github.com/bevry/dorothy/commits?author=wasdee 'View the GitHub contributions of Nutchanon Ninyawee on repository bevry/dorothy') -- [Sumit Rai](https://github.com/sumitrai) — [view contributions](https://github.com/bevry/dorothy/commits?author=sumitrai 'View the GitHub contributions of Sumit Rai on repository bevry/dorothy') +- [Benjamin Lupton](https://github.com/balupton) — [view contributions](https://github.com/bevry/dorothy/commits?author=balupton "View the GitHub contributions of Benjamin Lupton on repository bevry/dorothy") +- [Bevry Team](https://github.com/BevryMe) — [view contributions](https://github.com/bevry/dorothy/commits?author=BevryMe "View the GitHub contributions of Bevry Team on repository bevry/dorothy") +- [BJReplay](https://github.com/BJReplay) — [view contributions](https://github.com/bevry/dorothy/commits?author=BJReplay "View the GitHub contributions of BJReplay on repository bevry/dorothy") +- [molleweide](https://github.com/molleweide) — [view contributions](https://github.com/bevry/dorothy/commits?author=molleweide "View the GitHub contributions of molleweide on repository bevry/dorothy") +- [Nutchanon Ninyawee](https://github.com/wasdee) — [view contributions](https://github.com/bevry/dorothy/commits?author=wasdee "View the GitHub contributions of Nutchanon Ninyawee on repository bevry/dorothy") +- [Sumit Rai](https://github.com/sumitrai) — [view contributions](https://github.com/bevry/dorothy/commits?author=sumitrai "View the GitHub contributions of Sumit Rai on repository bevry/dorothy") ### Finances @@ -297,7 +298,6 @@ Join the [Bevry Software community](https://discord.gg/nQuXddV7VP) to stay up-to #### Sponsors - [Andrew Nesbitt](https://nesbitt.io) — Software engineer and researcher -- [Balsa](https://balsa.com) — We're Balsa, and we're building tools for builders. - [Codecov](https://codecov.io) — Empower developers with tools to improve code quality and testing. - [Frontend Masters](https://FrontendMasters.com) — The training platform for web app engineering skills – from front-end to full-stack! 🚀 - [Mr. Henry](https://mrhenry.be) diff --git a/commands.beta/echo-escape-special b/commands.beta/echo-escape-special index bdbaecaa8..e041d3f53 100755 --- a/commands.beta/echo-escape-special +++ b/commands.beta/echo-escape-special @@ -28,6 +28,9 @@ function echo_escape_special() ( # exit status: 0 EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } diff --git a/commands.beta/echo-if-directory b/commands.beta/echo-if-directory index 511b6d1f4..1fdc1735c 100755 --- a/commands.beta/echo-if-directory +++ b/commands.beta/echo-if-directory @@ -28,6 +28,9 @@ function echo_if_directory() ( # exit status: 0 EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } diff --git a/commands.beta/echo-if-empty b/commands.beta/echo-if-empty new file mode 100755 index 000000000..c60cbfc4b --- /dev/null +++ b/commands.beta/echo-if-empty @@ -0,0 +1,97 @@ +#!/usr/bin/env bash + +function echo_if_empty() ( + source "$DOROTHY/sources/stdinargs.bash" + + function help { + cat <<-EOF >/dev/stderr + ABOUT: + Output if is empty. + + USAGE: + echo-if-empty [...options] [--] ... + echo-lines ... | echo-if-empty [...options] + + OPTIONS: + | --fallback= + The fallback to use if is empty. + + $(stdinargs_options_help --) + + EXAMPLE: + + echo-if-empty 'my-fallback-value' + + my-fallback-value + # exit status: 0 + + echo | echo-if-empty 'my-fallback-value' + + my-fallback-value + # exit status: 0 + + echo 'a-value' | echo-if-empty 'my-fallback-value' + + 'a-value' + # exit status: 0 + + ALTERNATIVES: + Use [ifne] from [moreutils], which is what we use in [eval-on-empty-stdin] and [eval-on-not-empty-stdin]. + EOF + if test "$#" -ne 0; then + echo-error "$@" + fi + return 22 # EINVAL 22 Invalid argument + } + + # process our own arguments, delegate everything else to stdinargs + local rand="$RANDOM" + local item option_fallback="$rand" option_args=() + while test "$#" -ne 0; do + item="$1" + shift + case "$item" in + '--help' | '-h') help ;; + '--fallback='*) option_fallback="${item#*--fallback=}" ;; + '--') + option_args+=("$item" "$@") + shift $# + break + ;; + *) + if test "$option_fallback" = "$rand"; then + option_fallback="$item" + else + option_args+=("$item") + fi + ;; + esac + done + + # checck for expected + if test "$option_fallback" = "$rand"; then + help "Missing required argument: " + fi + + # action + local inputs='' + function on_inline { + inputs+="$1" + } + function on_line { + inputs+="$1"$'\n' + } + function on_finish { + if is-empty-string -- "$inputs"; then + print_string "$fallback" + else + print_string "$inputs" + fi + } + stdinargs "${option_args[@]}" +) + +# fire if invoked standalone +if test "$0" = "${BASH_SOURCE[0]}"; then + echo_if_empty "$@" +fi diff --git a/commands.beta/echo-if-executable b/commands.beta/echo-if-executable index d40e7b488..a4f5f88b2 100755 --- a/commands.beta/echo-if-executable +++ b/commands.beta/echo-if-executable @@ -18,7 +18,7 @@ function echo_if_executable() ( EXAMPLE: touch executable - chmodx +x executable + chmod +x executable touch file echo-if-file -- executable file missing @@ -32,6 +32,9 @@ function echo_if_executable() ( # exit status: 0 EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } diff --git a/commands.beta/echo-if-path b/commands.beta/echo-if-path index 6bd8e51ae..2513eb51a 100755 --- a/commands.beta/echo-if-path +++ b/commands.beta/echo-if-path @@ -28,11 +28,14 @@ function echo_if_path() ( # exit status: 0 EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } function on_input { - if is-present "$1"; then + if is-present -- "$1"; then print_line "$1" fi } diff --git a/commands.beta/echo-nonflags b/commands.beta/echo-nonflags index 59ff50384..e5954c77b 100755 --- a/commands.beta/echo-nonflags +++ b/commands.beta/echo-nonflags @@ -38,6 +38,9 @@ function echo_nonflags() ( code -a --b c # exit status: 0 EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } diff --git a/commands.beta/echo-numeric b/commands.beta/echo-numeric index 6da315937..d6ebd5314 100755 --- a/commands.beta/echo-numeric +++ b/commands.beta/echo-numeric @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# this command should have a --fallback (or be used with echo-on-empty-stdin), or a --quiet to suppress the error +# this command should have a --fallback (or be used with echo-trim-empty-lines), or a --quiet to suppress the error function echo_numeric() ( source "$DOROTHY/sources/stdinargs.bash" @@ -38,12 +38,15 @@ function echo_numeric() ( # exit status: 0, it was ignored due to || : EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } local had_an_invalid_input=no function on_input { - if is-number "$1"; then + if is-number -- "$1"; then print_line "$1" else echo-style --error="[$1] is not a number" >/dev/stderr diff --git a/commands.beta/echo-on-empty-stdin b/commands.beta/echo-on-empty-stdin deleted file mode 100755 index d4e35eda4..000000000 --- a/commands.beta/echo-on-empty-stdin +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env bash - -function echo_on_empty_stdin() ( - source "$DOROTHY/sources/stdinargs.bash" - - function help { - cat <<-EOF >/dev/stderr - ABOUT: - Output the arguments if STDIN is empty. - - USAGE: - echo-on-empty-stdin [...options] [--] ... - echo-lines ... | echo-on-empty-stdin [...options] - - OPTIONS: - $(stdinargs_options_help --stdin) - - EXAMPLE: - - echo-on-empty-stdin 'my-fallback-value' - - my-fallback-value - # exit status: 0 - - echo | echo-on-empty-stdin 'my-fallback-value' - - my-fallback-value - # exit status: 0 - - echo 'a-value' | echo-on-empty-stdin 'my-fallback-value' - - 'a-value' - # exit status: 0 - - ALTERNATIVES: - Use [ifne] from [moreutils], which is what we use in [eval-on-empty-stdin] and [eval-on-not-empty-stdin]. - EOF - return 22 # EINVAL 22 Invalid argument - } - - # process - local fallback="$1" - shift - - # action - local inputs='' - function on_arg { - help 'Use STDIN.' - } - function on_input { - inputs+="$1" - } - function on_finish { - if test -z "$inputs"; then - print_line "$fallback" - else - print_line "$inputs" - fi - } - stdinargs --stdin "$@" -) - -# fire if invoked standalone -if test "$0" = "${BASH_SOURCE[0]}"; then - echo_on_empty_stdin "$@" -fi diff --git a/commands.beta/echo-sort b/commands.beta/echo-sort index f16e66304..b17b8d690 100755 --- a/commands.beta/echo-sort +++ b/commands.beta/echo-sort @@ -43,6 +43,9 @@ function echo_sort() ( 1.1 1.2 EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } diff --git a/commands.beta/echo-values b/commands.beta/echo-values index d21fcc739..87c75528d 100755 --- a/commands.beta/echo-values +++ b/commands.beta/echo-values @@ -39,11 +39,14 @@ function echo_values() ( [3] = [z] EOF + if test "$#" -ne 0; then + echo-error "$@" + fi return 22 # EINVAL 22 Invalid argument } function on_input { - if is-value "$1"; then + if is-value -- "$1"; then print_line "$1" fi } diff --git a/commands.beta/edit-dns b/commands.beta/edit-dns index b258095e0..4fc24f759 100755 --- a/commands.beta/edit-dns +++ b/commands.beta/edit-dns @@ -40,7 +40,7 @@ function edit_dns() ( # this would work, but it is automatically generated from system preferences # edit /etc/resolv.conf - if get-app --quiet 'ProtonVPN.app'; then + if get-app --quiet -- 'ProtonVPN'; then print_line 'ProtonVPN enforces its own DNS' elif command-exists dnscrypt-proxy; then print_line 'Editing DNS configuration of dnscrypt-proxy' diff --git a/commands.beta/ensure-trailing-newline b/commands.beta/ensure-trailing-newline index 9219e121b..a945a5e75 100755 --- a/commands.beta/ensure-trailing-newline +++ b/commands.beta/ensure-trailing-newline @@ -21,32 +21,32 @@ function ensure_trailing_newline() ( } # process - local item paths=() + local item option_paths=() while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; '--') - paths+=("$@") + option_paths+=("$@") shift "$#" break ;; '--'*) help "An unrecognised flag was provided: $item" ;; - *) paths+=("$item") ;; + *) option_paths+=("$item") ;; esac done # check - if test "${#paths[@]}" -eq 0; then - help "No paths were provided" + if test "${#option_paths[@]}" -eq 0; then + help "No s provided" fi # ===================================== # Action local path result=0 - for path in "${paths[@]}"; do + for path in "${option_paths[@]}"; do if test -f "$path"; then if test "$(tail -n1 <"$path" | wc -l)" -eq 0; then if test -w "$path"; then diff --git a/commands.beta/ensure-trailing-slash b/commands.beta/ensure-trailing-slash index ffe7c1bd2..92c0ad468 100755 --- a/commands.beta/ensure-trailing-slash +++ b/commands.beta/ensure-trailing-slash @@ -22,32 +22,32 @@ function ensure_trailing_slash() ( } # process - local item paths=() + local item option_paths=() while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; '--') - paths+=("$@") + option_paths+=("$@") shift "$#" break ;; '--'*) help "An unrecognised flag was provided: $item" ;; - *) paths+=("$item") ;; + *) option_paths+=("$item") ;; esac done # check - if test "${#paths[@]}" -eq 0; then - help 'No was provided.' + if test "${#option_paths[@]}" -eq 0; then + help 'No s was provided.' fi # ===================================== # Action local path length - for path in "${paths[@]}"; do + for path in "${option_paths[@]}"; do if test -d "$path"; then if [[ $path != */ ]]; then print_line "$path/" diff --git a/commands.beta/example-generic-command b/commands.beta/example-generic-command index 08f3250e7..fb5ee5fda 100755 --- a/commands.beta/example-generic-command +++ b/commands.beta/example-generic-command @@ -44,7 +44,7 @@ function example_generic_command() ( case "$item" in '--help' | '-h') help ;; '--no-boolean'* | '--boolean'*) - option_boolean="$(get-flag-value boolean --missing="$option_boolean" -- "$item" | echo-affirmative --stdin)" + option_boolean="$(get-flag-value --affirmative --missing="$option_boolean" -- "$item")" ;; '--string='*) option_string="${item#*--string=}" ;; '--multistring='*) option_multistring+=("${item#*--multistring=}") ;; diff --git a/commands.beta/get-codec b/commands.beta/get-codec index 382eae911..22b830320 100755 --- a/commands.beta/get-codec +++ b/commands.beta/get-codec @@ -29,7 +29,7 @@ function get_codec() ( '--help' | '-h') help ;; '--path='*) option_path="${item#*--path=}" ;; '--no-trim'* | '--trim'*) - option_trim="$(get-flag-value trim --missing="$option_trim" -- "$item" | echo-affirmative --stdin)" + option_trim="$(get-flag-value --affirmative --missing="$option_trim" -- "$item")" ;; '--'*) help "An unrecognised flag was provided: $item" ;; *) @@ -56,7 +56,7 @@ function get_codec() ( # Action if test "$option_trim" = 'yes'; then - ffprobe -i "$option_path" |& rg -o 'Audio: ([\w\d-]+)' --replace '$1' + ffprobe -i "$option_path" |& rg --only-matching --regexp='Audio: ([\w\d-]+)' --replace='$1' else ffprobe -i "$option_path" fi diff --git a/commands.beta/icloud-helper b/commands.beta/icloud-helper index 076610b81..fac6d5fb1 100755 --- a/commands.beta/icloud-helper +++ b/commands.beta/icloud-helper @@ -37,14 +37,14 @@ function icloud_helper() ( } # process - local item action='' args=() + local item action='' option_args=() while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; '--') - args+=("$@") + option_args+=("$@") shift $# break ;; @@ -101,7 +101,7 @@ function icloud_helper() ( # Act if test "$(type -t "$action")" = 'function'; then - "$action" "${args[@]}" + "$action" "${option_args[@]}" else print_line "Action [$action] not yet implemented." >/dev/stderr return 78 # ENOSYS 78 Function not implemented diff --git a/commands.beta/is-empty-directory b/commands.beta/is-empty-directory index ba7ab672e..a732a9e48 100755 --- a/commands.beta/is-empty-directory +++ b/commands.beta/is-empty-directory @@ -21,25 +21,25 @@ function is_empty_directory() ( } # process - local item paths=() + local item option_paths=() while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; '--') - paths+=("$@") + option_paths+=("$@") shift "$#" break ;; '--'*) help "An unrecognised flag was provided: $item" ;; - *) paths+=("$item") ;; + *) option_paths+=("$item") ;; esac done # check - if test "${#paths[@]}" -eq 0; then - help "No s were provided." + if test "${#option_paths[@]}" -eq 0; then + help "No s provided." fi # ===================================== @@ -47,7 +47,7 @@ function is_empty_directory() ( # action local path result - for path in "${paths[@]}"; do + for path in "${option_paths[@]}"; do if test ! -d "$path"; then return 1 fi diff --git a/commands.beta/is-empty-size b/commands.beta/is-empty-size new file mode 100755 index 000000000..fb61a1b62 --- /dev/null +++ b/commands.beta/is-empty-size @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +# unfortunately, empty directories may still be 4096 bytes long +# which can be filtered by doing `du -t 4097` however `du -c` still reports such in total +# --apparent-size has no affect +# until this is resolved, this command serves no purpose + +function is_empty_size() ( + source "$DOROTHY/sources/bash.bash" + + # ===================================== + # Arguments + + function help { + cat <<-EOF >/dev/stderr + ABOUT: + Checks if had a file size of zero. + + USAGE: + is-empty-size [--] ... + + RETURNS: + [0] if all s were empty. + [1] if any s were not empty. + [2] if any were not a file. + EOF + if test "$#" -ne 0; then + echo-error "$@" + fi + return 22 # EINVAL 22 Invalid argument + } + + # process + local item option_paths=() + while test "$#" -ne 0; do + item="$1" + shift + case "$item" in + '--help' | '-h') help ;; + '--') + option_paths+=("$@") + shift "$#" + break + ;; + '--'*) help "An unrecognised flag was provided: $item" ;; + *) option_paths+=("$item") ;; + esac + done + + # check + if test "${#option_paths[@]}" -eq 0; then + help "No s provided." + fi + + # ===================================== + # Action + + # dependencies + setup-util-coreutils --quiet # du + + # process + local path + for path in "${option_paths[@]}"; do + if test ! -f "$path"; then + echo-error 'A path was was not a file: ' --code="$path" + return 2 + fi + test "$(du -s "$path")" = $'0\t'"$path" + done + return 0 +) + +# fire if invoked standalone +if test "$0" = "${BASH_SOURCE[0]}"; then + is_empty_size "$@" +fi diff --git a/commands.beta/is-even b/commands.beta/is-even index 1b3077667..18b2cffba 100755 --- a/commands.beta/is-even +++ b/commands.beta/is-even @@ -3,8 +3,68 @@ function is_even() ( source "$DOROTHY/sources/bash.bash" - local i="$1" - test "$((i % 2))" -eq 0 + # ===================================== + # Arguments + + # help + function help { + cat <<-EOF >/dev/stderr + ABOUT: + Checks if the is an even number. + + USAGE: + is-even [...options] [--] + + OPTIONS: + + Verify this is an even number + + RETURNS: + [0] if all s were odd numbers + [1] if any s were not odd numbers + [2] if any s were not numbers + EOF + if test "$#" -ne 0; then + echo-error "$@" + fi + return 22 # EINVAL 22 Invalid argument + } + + # process + local item inputs=() + while test "$#" -ne 0; do + item="$1" + shift + case "$item" in + '--help' | '-h') help ;; + '--') + inputs+=("$@") + shift $# + break + ;; + '--'*) help "An unrecognised flag was provided: $item" ;; + *) inputs+=("$item") ;; + esac + done + + # verify + if test "${#inputs[@]}" -eq 0; then + help "No s provided" + fi + + # verify + if ! is-number -- "${inputs[@]}"; then + return 2 + fi + + # ===================================== + # Action + + local input + for input in "${inputs[@]}"; do + test "$((input % 2))" -eq 0 + done + return 0 ) # fire if invoked standalone diff --git a/commands.beta/is-float b/commands.beta/is-float index a811cbf04..bade8a176 100755 --- a/commands.beta/is-float +++ b/commands.beta/is-float @@ -4,7 +4,7 @@ function is_float() ( source "$DOROTHY/sources/bash.bash" # https://stackoverflow.com/a/29234612/130638 - [[ $1 == ?(-)@(+([0-9]).*([0-9])|*([0-9]).+([0-9]))?(E?(-|+)+([0-9])) ]] + [[ $1 == ?(-)@(+([0-9]).*([0-9])|*([0-9]).+([0-9]))?(E?(-|+)+([0-9])) ]] || return # explicit return with [[ required for bash v3 ) # fire if invoked standalone diff --git a/commands.beta/is-needles b/commands.beta/is-needles deleted file mode 100755 index a20b77f16..000000000 --- a/commands.beta/is-needles +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -function is_needles() ( - source "$DOROTHY/sources/bash.bash" - - local args sep found item needles haystack needle - args=("${@:1}") - sep=0 - found='no' - for item in "${args[@]:sep}"; do - if test "$item" = '--'; then - found='yes' - break - fi - sep=$((sep + 1)) - done - - if test "$found" = 'no' -o "$sep" -eq 0; then - print_line 'USAGE: is-needles ... -- [...haystack]' >/dev/stderr - return 1 - fi - - needles=("${args[@]:0:sep}") - haystack=("${args[@]:sep+1}") - - for needle in "${needles[@]}"; do - for item in "${haystack[@]}"; do - if test "$item" = "$needle"; then - return 0 - fi - done - done - - return 1 -) - -# fire if invoked standalone -if test "$0" = "${BASH_SOURCE[0]}"; then - is_needles "$@" -fi diff --git a/commands.beta/is-password-usable b/commands.beta/is-password-usable index 2049e5b57..317519850 100755 --- a/commands.beta/is-password-usable +++ b/commands.beta/is-password-usable @@ -4,9 +4,6 @@ function is_password_usable() ( source "$DOROTHY/sources/bash.bash" - # dependencies - source "$DOROTHY/sources/ripgrep.bash" - # ===================================== # Arguments @@ -34,17 +31,16 @@ function is_password_usable() ( } # process - local item user='' + local item option_user='' while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; - '--no-quiet'* | '--quiet'* | '--no-verbose'* | '--verbose'*) ;; # handled by is-quiet-enabled '--'*) help "An unrecognised flag was provided: $item" ;; *) - if test -z "$user"; then - user="$item" + if test -z "$option_user"; then + option_user="$item" else help "An unrecognised argument was provided: $item" fi @@ -53,14 +49,14 @@ function is_password_usable() ( done # ensure url - if test -z "$user"; then - user="$(whoami)" + if test -z "$option_user"; then + option_user="$(whoami)" fi # ===================================== # Act - sudo-helper -- passwd --status "$user" | rg --quiet --fixed-strings --regexp="$user P" + sudo-helper -- passwd --status "$option_user" | grep --quiet --fixed-strings --regexp="$option_user P" ) # fire if invoked standalone diff --git a/commands.beta/is-values b/commands.beta/is-values deleted file mode 100755 index 86f398f8d..000000000 --- a/commands.beta/is-values +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -function is_values() ( - source "$DOROTHY/sources/bash.bash" - - local arg - for arg in "$@"; do - if is-value "$arg"; then - return 0 - fi - done - - return 1 -) - -# fire if invoked standalone -if test "$0" = "${BASH_SOURCE[0]}"; then - is_values "$@" -fi diff --git a/commands.beta/itunes-owners b/commands.beta/itunes-owners index bf23b2061..dd2975438 100755 --- a/commands.beta/itunes-owners +++ b/commands.beta/itunes-owners @@ -53,7 +53,7 @@ function itunes_owners() ( local song_count=0 function fetch_songs { echo-style --h2="Fetching songs to $song_list" - rg -o 'file://(.+)' --replace '$1' <"$database" | + rg --only-matching --regexp='file://(.+)' --replace='$1' <"$database" | echo-url-decode --stdin | echo-html-decode --stdin >"$song_list" song_count="$(wc -l <"$song_list" | xargs)" @@ -74,7 +74,7 @@ function itunes_owners() ( fi # fetch owner - owner="$(ffprobe -i "$song" |& rg -o 'account_id\s*:\s*(.+)' --replace '$1' || :)" + owner="$(ffprobe -i "$song" |& rg --only-matching --regexp='account_id\s*:\s*(.+)' --replace='$1' || :)" # write if test -n "$owner"; then diff --git a/commands.beta/mac-address-helper b/commands.beta/mac-address-helper index 7570cd6a9..bb0b4fe9c 100755 --- a/commands.beta/mac-address-helper +++ b/commands.beta/mac-address-helper @@ -31,7 +31,7 @@ function mac_address_helper() ( } # process - local item action='' args=() + local item action='' option_args=() while test "$#" -ne 0; do item="$1" shift @@ -40,7 +40,7 @@ function mac_address_helper() ( '--'*) help "An unrecognised flag was provided: $item" ;; *) action="$item" - args+=("$@") + option_args+=("$@") shift $# break ;; @@ -78,14 +78,14 @@ function mac_address_helper() ( if test -z "$interface"; then help " was missing for:" " mac-address-helper get " '' "Typically [en0] or [p2p0] is used." fi - sudo-helper -- ifconfig "$interface" ether | rg -o 'ether ([\w\d:]+)' --replace '$1' + sudo-helper -- ifconfig "$interface" ether | rg --only-matching --regexp='ether ([\w\d:]+)' --replace='$1' } # ===================================== # Act if test "$(type -t "act_$action")" = 'function'; then - "act_$action" "${args[@]}" + "act_$action" "${option_args[@]}" else echo-style --error="Action [$action] not yet implemented." >/dev/stderr return 78 # ENOSYS 78 Function not implemented diff --git a/commands.beta/macos-settings b/commands.beta/macos-settings index 0cb560836..7dac85e2b 100755 --- a/commands.beta/macos-settings +++ b/commands.beta/macos-settings @@ -93,7 +93,7 @@ function macos_settings() ( defaults delete com.apple.dock autohide-time-modifier &>/dev/null || : - if is-needle dockside "${choices[@]}"; then + if is-needle --needle=dockside -- "${choices[@]}"; then local dock_side dock_side="$( choose-option \ @@ -104,9 +104,9 @@ function macos_settings() ( echo fi - if is-needle dockhide "${choices[@]}"; then + if is-needle --needle=dockhide -- "${choices[@]}"; then defaults write com.apple.dock autohide -bool true - if is-needle dockinstant "${choices[@]}"; then + if is-needle --needle=dockinstant -- "${choices[@]}"; then defaults write com.apple.dock autohide-delay -float 0 else defaults delete com.apple.dock autohide-delay &>/dev/null || : @@ -115,23 +115,23 @@ function macos_settings() ( defaults delete com.apple.dock autohide &>/dev/null || : fi - if is-needle dockmin "${choices[@]}"; then + if is-needle --needle=dockmin -- "${choices[@]}"; then defaults write com.apple.dock minimize-to-application -bool true else defaults delete com.apple.dock minimize-to-application &>/dev/null || : fi - if is-needle docksmall "${choices[@]}"; then + if is-needle --needle=docksmall -- "${choices[@]}"; then defaults write com.apple.dock tilesize -int 32 fi - if is-needle groupwin "${choices[@]}"; then + if is-needle --needle=groupwin -- "${choices[@]}"; then defaults write com.apple.dock expose-group-apps -bool true else defaults delete com.apple.dock expose-group-apps &>/dev/null || : fi - if is-needle manualspaces "${choices[@]}"; then + if is-needle --needle=manualspaces -- "${choices[@]}"; then defaults write com.apple.dock mru-spaces -bool false else defaults delete com.apple.dock mru-spaces &>/dev/null || : @@ -140,29 +140,29 @@ function macos_settings() ( # ------------------------------------- # Safari - if is-needle safarinopass "${choices[@]}"; then + if is-needle --needle=safarinopass -- "${choices[@]}"; then defaults write com.apple.Safari AutoFillPasswords -bool false else defaults delete com.apple.Safari AutoFillPasswords &>/dev/null || : fi - if is-needle safarinohome "${choices[@]}"; then + if is-needle --needle=safarinohome -- "${choices[@]}"; then defaults write com.apple.Safari HomePage -string 'about:blank' fi - if is-needle safarifullurls "${choices[@]}"; then + if is-needle --needle=safarifullurls -- "${choices[@]}"; then defaults write com.apple.Safari ShowFullURLInSmartSearchField -bool true else defaults delete com.apple.Safari ShowFullURLInSmartSearchField &>/dev/null || : fi - if is-needle safarinoopen "${choices[@]}"; then + if is-needle --needle=safarinoopen -- "${choices[@]}"; then defaults write com.apple.Safari AutoOpenSafeDownloads -bool false else defaults delete com.apple.Safari AutoOpenSafeDownloads &>/dev/null || : fi - if is-needle safarinobar "${choices[@]}"; then + if is-needle --needle=safarinobar -- "${choices[@]}"; then defaults write com.apple.Safari ShowFavoritesBar-v2 -bool false else defaults delete write com.apple.Safari ShowFavoritesBar-v2 &>/dev/null || : @@ -171,45 +171,45 @@ function macos_settings() ( # ------------------------------------- # Finder - if is-needle finderhome "${choices[@]}"; then + if is-needle --needle=finderhome -- "${choices[@]}"; then defaults write com.apple.finder NewWindowTargetPath "file://$HOME" fi # https://software.com/mac/tweaks/show-file-extensions-in-finder - if is-needle allextensions "${choices[@]}"; then + if is-needle --needle=allextensions -- "${choices[@]}"; then defaults write NSGlobalDomain AppleShowAllExtensions -bool true else defaults delete NSGlobalDomain AppleShowAllExtensions &>/dev/null || : fi # https://software.com/mac/tweaks/show-all-files-in-finder - if is-needle showhidden "${choices[@]}"; then + if is-needle --needle=showhidden -- "${choices[@]}"; then defaults write com.apple.finder AppleShowAllFiles -bool true else defaults delete com.apple.finder AppleShowAllFiles &>/dev/null || : fi # http://osxdaily.com/2012/04/11/disable-the-file-extension-change-warning-in-mac-os-x/ - if is-needle hideextwarn "${choices[@]}"; then + if is-needle --needle=hideextwarn -- "${choices[@]}"; then defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false else defaults delete com.apple.finder FXEnableExtensionChangeWarning &>/dev/null || : fi - if is-needle showstatusbar "${choices[@]}"; then + if is-needle --needle=showstatusbar -- "${choices[@]}"; then defaults write com.apple.finder ShowStatusBar -bool false else defaults delete com.apple.finder ShowStatusBar &>/dev/null || : fi - if is-needle hidetrashwarn "${choices[@]}"; then + if is-needle --needle=hidetrashwarn -- "${choices[@]}"; then defaults write com.apple.finder WarnOnEmptyTrash -bool false else defaults delete write com.apple.finder WarnOnEmptyTrash &>/dev/null || : fi # https://software.com/mac/tweaks/hide-desktop-icons - if is-needle hidedesktop "${choices[@]}"; then + if is-needle --needle=hidedesktop -- "${choices[@]}"; then defaults write com.apple.finder CreateDesktop -bool false defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool false defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false @@ -227,27 +227,27 @@ function macos_settings() ( # ------------------------------------- # Global - if is-needle screenshotdir "${choices[@]}"; then + if is-needle --needle=screenshotdir -- "${choices[@]}"; then mkdir -p "$HOME/Desktop/Screenshots" defaults write com.apple.screencapture location "$HOME/Desktop/Screenshots" else defaults delete com.apple.screencapture location &>/dev/null || : fi - if is-needle disableautocorrect "${choices[@]}"; then + if is-needle --needle=disableautocorrect -- "${choices[@]}"; then defaults write NSGlobalDomain NSAutomaticSpellingCorrectionEnabled -bool false else defaults delete NSGlobalDomain NSAutomaticSpellingCorrectionEnabled &>/dev/null || : fi - if is-needle updatedaily "${choices[@]}"; then + if is-needle --needle=updatedaily -- "${choices[@]}"; then defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1 else defaults delete com.apple.SoftwareUpdate ScheduleFrequency &>/dev/null || : fi # https://en.wikipedia.org/wiki/Apple_Developer_Tools#CrashReporterPrefs - if is-needle devcrashes "${choices[@]}"; then + if is-needle --needle=devcrashes -- "${choices[@]}"; then defaults write com.apple.CrashReporter DialogType -string 'developer' else defaults delete com.apple.CrashReporter DialogType &>/dev/null || : diff --git a/commands.beta/macos-state b/commands.beta/macos-state index 7515b92ad..dce893715 100755 --- a/commands.beta/macos-state +++ b/commands.beta/macos-state @@ -200,7 +200,7 @@ function macos_state() ( function do_remove { local path="$1" - if is-present "$path"; then + if is-present -- "$path"; then if confirm --positive --ppid=$$ -- "^ will be replaced, continue?"; then sudo-helper -- rm -Rf "$path" fi @@ -227,7 +227,7 @@ function macos_state() ( $to EOF - if is-present "$from"; then + if is-present -- "$from"; then if test "$backup_type" = 'remote'; then # @todo will "${from@Q}" work? cpr -- "$from" "$to" @@ -260,7 +260,7 @@ function macos_state() ( do_replace "$to" # @todo will "${from@Q}" work? cpr -- "$from" "$to" - elif is-present "$from"; then + elif is-present -- "$from"; then do_replace "$to" cpr -- "$from" "$to" else diff --git a/commands.beta/mail-sync b/commands.beta/mail-sync index d343309c8..dcf4c1f55 100755 --- a/commands.beta/mail-sync +++ b/commands.beta/mail-sync @@ -45,7 +45,7 @@ function mail_sync() ( return 22 # EINVAL 22 Invalid argument } - # process + # process, @todo rewrite with option_ prefix local item args=() user1='' user2='' password1='' password2='' type1='' type2='' while test "$#" -ne 0; do item="$1" diff --git a/commands.beta/setup-server b/commands.beta/setup-server index 4c3e42fc6..bdfee8689 100755 --- a/commands.beta/setup-server +++ b/commands.beta/setup-server @@ -109,7 +109,7 @@ function setup_server() ( case "$item" in '--help' | '-h') help ;; '--no-reload'* | '--reload'*) - option_reload="$(get-flag-value reload --missing="$option_reload" -- "$item" | echo-affirmative --stdin)" + option_reload="$(get-flag-value --affirmative --fallback="$option_reload" -- "$item")" ;; '--'*) help "An unrecognised flag was provided: $item" ;; *) help "An unrecognised argument was provided: $item" ;; @@ -125,7 +125,7 @@ function setup_server() ( # handle share user if desired if test -n "$SHARE_USER"; then # create share user if necessary - if ! is-user "$SHARE_USER"; then + if ! is-user -- "$SHARE_USER"; then # create user sudo-helper -- useradd "$SHARE_USER" || : fi @@ -144,7 +144,7 @@ function setup_server() ( fi # create share group if desired and necessary - if test -n "$SHARE_GROUP" && ! is-group "$SHARE_GROUP"; then + if test -n "$SHARE_GROUP" && ! is-group -- "$SHARE_GROUP"; then sudo-helper -- groupadd "$SHARE_GROUP" || : fi @@ -152,12 +152,12 @@ function setup_server() ( local user group for user in "${users[@]}"; do # user doesn't exist (service user that we don't care about for this hostname) - if ! is-user "$user"; then + if ! is-user -- "$user"; then continue fi for group in "${groups[@]}"; do # group doesn't exist (service group that we don't care about for this hostname) - if ! is-group "$group"; then + if ! is-group -- "$group"; then continue fi # skip if user already inside the group @@ -186,7 +186,7 @@ function setup_server() ( # setup owner local OWNER_MOUNT=() if test -n "$SHARE_USER" -a -n "$SHARE_GROUP"; then - if is-user "$SHARE_USER" && is-group "$SHARE_GROUP" && is-user-in-group --user="$me" --group="$SHARE_GROUP"; then + if is-user -- "$SHARE_USER" && is-group -- "$SHARE_GROUP" && is-user-in-group --user="$me" --group="$SHARE_GROUP"; then owner="$(get-user-id "$SHARE_USER"):$(get-group-id "$SHARE_GROUP")" else setup_owner --reload='yes' @@ -209,57 +209,57 @@ function setup_server() ( # https://support.plex.tv/articles/201105343-advanced-hidden-server-settings/ # https://support.plex.tv/articles/202915258-where-is-the-plex-media-server-data-directory-located/ temp='/var/lib/plexmediaserver' - if is-present "$temp" && test -n "$PLEX_HOME"; then - if is-missing "$PLEX_HOME"; then + if is-present -- "$temp" && test -n "$PLEX_HOME"; then + if is-missing -- "$PLEX_HOME"; then sudo-helper -- mv -v "$temp" "$PLEX_HOME" else echo-style --warning="Both [$temp] and [$PLEX_HOME] exist" fi fi - if is-present "$temp"; then + if is-present -- "$temp"; then paths+=("$temp") fi - if is-present "$PLEX_HOME"; then + if is-present -- "$PLEX_HOME"; then paths+=("$PLEX_HOME") fi # syncthing # https://docs.syncthing.net/users/config.html temp="$XDG_CONFIG_HOME/syncthing" - if is-present "$temp" && test -n "$SYNCTHING_HOME"; then - if is-missing "$SYNCTHING_HOME"; then + if is-present -- "$temp" && test -n "$SYNCTHING_HOME"; then + if is-missing -- "$SYNCTHING_HOME"; then sudo-helper -- mv -v "$temp" "$SYNCTHING_HOME" else echo-style --warning="Both [$temp] and [$SYNCTHING_HOME] exist" fi fi - if is-present "$temp"; then + if is-present -- "$temp"; then paths+=("$temp") fi - if is-present "$SYNCTHING_HOME"; then + if is-present -- "$SYNCTHING_HOME"; then paths+=("$SYNCTHING_HOME") fi temp="$HOME/Sync" - if is-present "$temp"; then + if is-present -- "$temp"; then paths+=("$temp") fi # transmission temp='/var/lib/transmission-daemon' - if is-present "$temp" && test -n "$TRANSMISSION_HOME"; then - if is-missing "$TRANSMISSION_HOME"; then + if is-present -- "$temp" && test -n "$TRANSMISSION_HOME"; then + if is-missing -- "$TRANSMISSION_HOME"; then sudo-helper -- mv -v "$temp" "$TRANSMISSION_HOME" else echo-style --warning="Both [$temp] and [$TRANSMISSION_HOME] exist" fi fi - if is-present "$temp"; then + if is-present -- "$temp"; then paths+=("$temp") fi - if is-present "$TRANSMISSION_HOME"; then + if is-present -- "$TRANSMISSION_HOME"; then paths+=("$TRANSMISSION_HOME") # clear the log as it goes on forever - if is-present "$TRANSMISSION_HOME/transmission.log"; then + if is-present -- "$TRANSMISSION_HOME/transmission.log"; then sudo-helper -- truncate -s0 "$TRANSMISSION_HOME/transmission.log" fi fi @@ -358,7 +358,7 @@ function setup_server() ( # verify firewall, this is curcial for killswitch to work nordvpn set firewall on || : # or to prevent already enabled errors waiter 5 # this can take a while for changes to be reflected - if ! nordvpn settings | echo-wait | grep -q 'Firewall: enabled'; then + if ! nordvpn settings | echo-wait | grep --quiet --fixed-strings --regexp='Firewall: enabled'; then echo-style --error='Firewall failed to enable. Reboot your machine.' return 2 fi @@ -366,7 +366,7 @@ function setup_server() ( # verify killswitch nordvpn set killswitch on || : # or to prevent already enabled errors waiter 5 # this can take a while for changes to be reflected - if ! nordvpn settings | echo-wait | grep -q 'Kill Switch: enabled'; then + if ! nordvpn settings | echo-wait | grep --quiet --fixed-strings --regexp='Kill Switch: enabled'; then echo-style --error='Killswitch failed to enable. Reboot your machine.' return 2 fi @@ -377,11 +377,11 @@ function setup_server() ( # verify nordvpn connection local vpn_address vpn_prefix clear_address clear_prefix - if nordvpn status | grep -q 'Status: Connected'; then - vpn_address="$(nordvpn status | rg -o '(?:Server )?IP: (.+)' --replace '$1')" - vpn_prefix="$(print_line "$vpn_address" | rg -o '^[0-9]+[.][0-9]+[.][0-9]+[.]')" + if nordvpn status | grep --quiet --fixed-strings --regexp='Status: Connected'; then + vpn_address="$(nordvpn status | rg --only-matching --regexp='(?:Server )?IP: (.+)' --replace='$1')" + vpn_prefix="$(print_line "$vpn_address" | rg --only-matching --regexp='^[0-9]+[.][0-9]+[.][0-9]+[.]')" clear_address="$(what-is-my-ip remote)" - clear_prefix="$(print_line "$clear_address" | rg -o '^[0-9]+[.][0-9]+[.][0-9]+[.]')" + clear_prefix="$(print_line "$clear_address" | rg --only-matching --regexp='^[0-9]+[.][0-9]+[.][0-9]+[.]')" if test "$vpn_prefix" = "$clear_prefix"; then echo-style --success="Successfully connected [$clear_address] to NordVPN [$vpn_address]." else @@ -763,14 +763,14 @@ function setup_server() ( } # process - local item action='' args=() + local item action='' option_args=() while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; '--') - args+=("$@") + option_args+=("$@") shift $# break ;; @@ -795,7 +795,7 @@ function setup_server() ( if test -z "$action"; then help "No provided." elif test "$(type -t "act_$action")" = 'function'; then - "act_$action" "${args[@]}" + "act_$action" "${option_args[@]}" else echo-error "$0: Action not yet implemented: $action" return 78 # ENOSYS 78 Function not implemented diff --git a/commands.beta/svg-export b/commands.beta/svg-export index 2cda6d09a..19d353c8d 100755 --- a/commands.beta/svg-export +++ b/commands.beta/svg-export @@ -70,7 +70,7 @@ function svg_export() ( # if no files, fail if test "${#files[@]}" -eq 0; then - help 'No s were provided.' + help 'No s provided.' fi # ensure correct format diff --git a/commands.beta/trim-audio b/commands.beta/trim-audio index 0762a3f35..a373b00cf 100755 --- a/commands.beta/trim-audio +++ b/commands.beta/trim-audio @@ -39,7 +39,7 @@ function trim_audio() ( # check if test "${#files[@]}" -eq 0; then - help 'No was provided.' + help 'No s provided.' fi # ===================================== diff --git a/commands.beta/twitter-helper b/commands.beta/twitter-helper index 17bdc86d5..2c23a2599 100755 --- a/commands.beta/twitter-helper +++ b/commands.beta/twitter-helper @@ -45,7 +45,7 @@ function twitter_helper() ( } # process - local item action='' args=() + local item action='' option_args=() while test "$#" -ne 0; do item="$1" shift @@ -54,7 +54,7 @@ function twitter_helper() ( '--'*) help "An unrecognised flag was provided: $item" ;; *) action="$item" - args+=("$@") + option_args+=("$@") shift $# break ;; @@ -162,7 +162,7 @@ function twitter_helper() ( case "$action" in 'advertisers' | 'tweets' | 'delete' | 'block' | 'mute') # trunk-ignore(shellcheck/SC2031) - "$action" "${args[@]}" + "$action" "${option_args[@]}" ;; *) help "Unknown action: $action" diff --git a/commands.beta/video-merge b/commands.beta/video-merge index a09564a13..b83489120 100755 --- a/commands.beta/video-merge +++ b/commands.beta/video-merge @@ -80,7 +80,7 @@ function video_merge() ( output="$(fs-absolute -- "$output")" # check if the output file already exists, if it does, prompt for removal otherwise fail - if is-present "$output"; then + if is-present -- "$output"; then if confirm --positive --ppid=$$ -- "The output file already exists, remove it?" "$(echo-style --code="$output")"; then rm "$output" else diff --git a/commands.beta/xps2pdf b/commands.beta/xps2pdf index c40c3c64d..61085f4d7 100755 --- a/commands.beta/xps2pdf +++ b/commands.beta/xps2pdf @@ -36,25 +36,25 @@ function xps2pdf_() ( } # process - local item paths=() + local item option_paths=() while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; '--') - paths+=("$@") + option_paths+=("$@") shift "$#" break ;; '--'*) help "An unrecognised flag was provided: $item" ;; - *) paths+=("$item") ;; + *) option_paths+=("$item") ;; esac done # check - if test "${#paths[@]}" -eq 0; then - help 'No s were provided.' + if test "${#option_paths[@]}" -eq 0; then + help 'No s provided.' fi # ===================================== @@ -67,7 +67,7 @@ function xps2pdf_() ( local xps pdf ctime echo-style --bold="Converting " --code="${#paths[@]}" --bold=" files" - for xps in "${paths[@]}"; do + for xps in "${option_paths[@]}"; do pdf="${xps%.xps}.pdf" echo-style --bold="Converting " --code="$xps" --bold=" to " --code="$pdf" diff --git a/commands/alias-helper b/commands/alias-helper index a8b7c5aa2..5d4fd3694 100755 --- a/commands/alias-helper +++ b/commands/alias-helper @@ -37,14 +37,14 @@ function alias_helper() ( } # process - local item action='' args=() + local item action='' option_args=() while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; '--') - args+=("$@") + option_args+=("$@") shift $# break ;; @@ -225,7 +225,7 @@ function alias_helper() ( # Act if test "$(type -t "do_$action")" = 'function'; then - "do_$action" "${args[@]}" + "do_$action" "${option_args[@]}" else help " unsupported or yet implemented: $action" || : return 78 # ENOSYS 78 Function not implemented diff --git a/commands/ask b/commands/ask index 2034e4fff..00fbda85c 100755 --- a/commands/ask +++ b/commands/ask @@ -111,13 +111,13 @@ function ask_() ( '--default='*) option_default="${item#*--default=}" ;; '--timeout='*) option_timeout="${item#*--timeout=}" ;; '--no-password'* | '--password'*) - option_password="$(get-flag-value password --missing="$option_password" -- "$item" | echo-affirmative --stdin)" + option_password="$(get-flag-value --affirmative --missing="$option_password" -- "$item")" ;; '--no-required'* | '--required'*) - option_required="$(get-flag-value required --missing="$option_required" -- "$item" | echo-affirmative --stdin)" + option_required="$(get-flag-value --affirmative --missing="$option_required" -- "$item")" ;; '--no-confirm'* | '--confirm'*) - option_confirm="$(get-flag-value confirm --missing="$option_confirm" -- "$item" | echo-affirmative --stdin)" + option_confirm="$(get-flag-value --affirmative --missing="$option_confirm" -- "$item")" ;; '--') args+=("$@") @@ -143,7 +143,7 @@ function ask_() ( # helpers function on_timeout { - if is-value "$RESULT"; then + if is-value -- "$RESULT"; then echo-style --notice="Ask timed out, using fallback value: " --code="$RESULT" >/dev/stderr sleep 5 print_line "$RESULT" @@ -170,7 +170,7 @@ function ask_() ( if test "$__read_status" -eq 142; then return 60 # ETIMEDOUT 60 Operation timed out fi - if is-value "$RESULT"; then + if is-value -- "$RESULT"; then break elif test "$option_required" = 'no'; then RESULT='' @@ -181,7 +181,7 @@ function ask_() ( } function do_validate { local choose_status ask_status choice choices=() - if is-value "$RESULT"; then + if is-value -- "$RESULT"; then # we have a value, so go for it if test "$option_confirm" != 'yes'; then print_line "$RESULT" @@ -212,7 +212,7 @@ function ask_() ( fi # as need to confirm, adjust the timeout - if test -z "$option_timeout" && (is-value "$RESULT" || test "$option_required" = 'no'); then + if test -z "$option_timeout" && (is-value -- "$RESULT" || test "$option_required" = 'no'); then # timeout of one minute for confirms of existing values, or optional values option_timeout=60 fi diff --git a/commands/brew b/commands/brew index 314dc2688..959858c01 100755 --- a/commands/brew +++ b/commands/brew @@ -23,7 +23,9 @@ function brew_() ( fi fi - # help + # ===================================== + # Arguments + function help { if test -n "$bin"; then "$bin" --help || : @@ -57,6 +59,9 @@ function brew_() ( help >/dev/stderr fi + # ===================================== + # Action + # run brew if test -n "${HOMEBREW_ARCH-}"; then arch -"$HOMEBREW_ARCH" \ diff --git a/commands/brew-installed b/commands/brew-installed index f17b3cefa..3a6d055d0 100755 --- a/commands/brew-installed +++ b/commands/brew-installed @@ -44,7 +44,7 @@ function brew_installed() ( } # process - local item requested='no' packages=() brew_type brew_list_cmd brew_info_cmd deno_script_args + local item option_requested='no' packages=() brew_type brew_list_cmd brew_info_cmd deno_script_args brew_type='' # empty, formula, cask brew_list_cmd=( 'brew' @@ -66,7 +66,7 @@ function brew_installed() ( '--formula' | '--formulae') brew_type='formula' ;; '--cask' | '--casks') brew_type='cask' ;; '--no-requested'* | '--requested'*) - requested="$(get-flag-value requested --missing="$requested" -- "$item" | echo-affirmative --stdin)" + option_requested="$(get-flag-value --affirmative --fallback="$option_requested")" ;; '--') packages+=("$@") @@ -166,7 +166,7 @@ function brew_installed() ( } # get names of requested packages - if test "$requested" = 'no'; then + if test "$option_requested" = 'no'; then do_brew_simple elif test "${#packages[@]}" -eq 0; then do_brew_advanced diff --git a/commands/btrfs-helper b/commands/btrfs-helper index d131ae734..b6dd9bf79 100755 --- a/commands/btrfs-helper +++ b/commands/btrfs-helper @@ -46,7 +46,7 @@ function btrfs_helper() ( } # process - local item action='' args=() + local item action='' option_args=() while test "$#" -ne 0; do item="$1" shift @@ -57,7 +57,7 @@ function btrfs_helper() ( if test "${1-}" = '--'; then shift fi - args+=("$@") + option_args+=("$@") shift $# break ;; @@ -376,7 +376,7 @@ function btrfs_helper() ( if test -z "$action"; then help 'No specified.' elif test "$(type -t "act_$action")" = 'function'; then - "act_$action" "${args[@]}" + "act_$action" "${option_args[@]}" else help " unsupported or yet implemented: $action" || : return 78 # ENOSYS 78 Function not implemented diff --git a/commands/checksum b/commands/checksum index 5c909488d..06511e5b0 100755 --- a/commands/checksum +++ b/commands/checksum @@ -53,24 +53,24 @@ function checksum_() ( } # process - local item path paths=() relative='no' untitled='no' summary='no' algorithm='' + local item option_paths=() option_relative='no' option_untitled='no' option_summary='no' option_algorithm='' while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; '--no-relative'* | '--relative'*) - relative="$(get-flag-value relative --missing="$relative" -- "$item" | echo-affirmative --stdin)" + option_relative="$(get-flag-value --affirmative --missing="$option_relative" -- "$item")" ;; '--no-untitled'* | '--untitled'*) - untitled="$(get-flag-value untitled --missing="$untitled" -- "$item" | echo-affirmative --stdin)" + option_untitled="$(get-flag-value --affirmative --missing="$option_untitled" -- "$item")" ;; '--no-summary'* | '--summary'*) - summary="$(get-flag-value summary --missing="$summary" -- "$item" | echo-affirmative --stdin)" + option_summary="$(get-flag-value --affirmative --missing="$option_summary" -- "$item")" ;; - '--algorithm='*) algorithm="${item#*--algorithm=}" ;; + '--algorithm='*) option_algorithm="${item#*--algorithm=}" ;; '--') - mapfile -t paths < <(fs-absolute -- "$@") + mapfile -t option_paths < <(fs-absolute -- "$@") shift $# break ;; @@ -80,15 +80,15 @@ function checksum_() ( done # ensure algorithm - algorithm="$( + option_algorithm="$( choose-option --required \ --question='Which checksum algorithm do you wish to use?' \ - --filter="$algorithm" -- "${algorithms[@]}" + --filter="$option_algorithm" -- "${algorithms[@]}" )" # ensure paths - if test "${#paths[@]}" -eq 0; then - paths+=("$(pwd)") + if test "${#option_paths[@]}" -eq 0; then + option_paths+=("$(pwd)") fi # ===================================== @@ -109,9 +109,9 @@ function checksum_() ( fi # algorithm - "$algorithm" | { + "$option_algorithm" | { IFS=' ' read -ra hash_dot - if test "$untitled" = 'yes'; then + if test "$option_untitled" = 'yes'; then print_line "${hash_dot[0]}" else print_line "${hash_dot[0]} $path" @@ -128,9 +128,9 @@ function checksum_() ( done } function do_checksum_of_paths { - local path temp_file use_relative="${2:-"$relative"}" + local path temp_file use_relative="${2:-"$option_relative"}" for path in "$@"; do - if test -f "$path" -o "$summary" != 'yes'; then + if test -f "$path" -o "$option_summary" != 'yes'; then # file, or itemise do_checksum_of_file_or_directory "$path" "$use_relative" else @@ -144,7 +144,7 @@ function checksum_() ( } # act - do_checksum_of_paths "${paths[@]}" + do_checksum_of_paths "${option_paths[@]}" ) # fire if invoked standalone diff --git a/commands/choose-menu b/commands/choose-menu index f9cbd44b8..45f448db2 100755 --- a/commands/choose-menu +++ b/commands/choose-menu @@ -130,13 +130,13 @@ function choose_menu() ( # process local item='' items=() defaults=() tmp=() option_question='' option_timeout='' option_multi='no' option_required='no' option_hints='yes' use_colors - use_colors="$(is-color-enabled yes -- "$@")" + use_colors="$(echo-color-enabled --fallback=yes -- "$@")" while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; - '--no-color'* | '--color'*) ;; # handled by is-color-enabled + '--no-color'* | '--color'*) ;; # handled by echo-color-enabled '--default='*) defaults+=("${item#*--default=}") ;; '--defaults='*) mapfile -t tmp <<<"${item#*--defaults=}" @@ -145,13 +145,13 @@ function choose_menu() ( '--question='*) option_question="${item#*--question=}" ;; '--timeout='*) option_timeout="${item#*--timeout=}" ;; '--no-hints'* | '--hints'*) - option_hints="$(get-flag-value hints --missing="$option_hints" -- "$item" | echo-affirmative --stdin)" + option_hints="$(get-flag-value --affirmative --missing="$option_hints" -- "$item")" ;; '--no-multi'* | '--multi'*) - option_multi="$(get-flag-value multi --missing="$option_multi" -- "$item" | echo-affirmative --stdin)" + option_multi="$(get-flag-value --affirmative --missing="$option_multi" -- "$item")" ;; '--no-required'* | '--required'*) - option_required="$(get-flag-value required --missing="$option_required" -- "$item" | echo-affirmative --stdin)" + option_required="$(get-flag-value --affirmative --missing="$option_required" -- "$item")" ;; '--') items+=("$@") @@ -165,9 +165,9 @@ function choose_menu() ( # ensure we have items if test "${#items[@]}" -eq 0; then - help 'No s were provided.' - elif is-array-partial "${items[@]}"; then - help 'Empty s were provided:' $'\n' "$(echo-verbose -- "${items[@]}")" + help 'No s provided.' + elif is-array-partial -- "${items[@]}"; then + help 'Empty s provided:' $'\n' "$(echo-verbose -- "${items[@]}")" fi # prepare vars @@ -595,7 +595,10 @@ function choose_menu() ( fi # perform action - if is-digit "$action"; then + if is-digit -- "$action"; then + if is-ci; then + print_string "DIGIT=[$action]" >/dev/stderr + fi action_jump elif test "$action" = 'up' -o "$action" = 'left' -o "$action" = 'h' -o "$action" = 'k' -o "$action" = 'w'; then action_up diff --git a/commands/choose-option b/commands/choose-option index fd0ba626e..a2edb9e93 100755 --- a/commands/choose-option +++ b/commands/choose-option @@ -132,13 +132,13 @@ function choose_option() ( # label can be 'yes', 'no', and 'first' local option_label='no' local option_hints='yes' option_multi='no' option_required='no' option_confirm='no' use_colors - use_colors="$(is-color-enabled yes -- "$@")" + use_colors="$(echo-color-enabled --fallback=yes -- "$@")" while test "$#" -ne 0; do item="$1" shift case "$item" in '--help' | '-h') help ;; - '--no-color'* | '--color'*) ;; # handled by is-color-enabled + '--no-color'* | '--color'*) ;; # handled by echo-color-enabled '--question='*) option_question="${item#*--question=}" ;; '--default='*) defaults+=("${item#*--default=}") ;; '--defaults='*) @@ -150,19 +150,19 @@ function choose_option() ( '--visual='*) option_visual="${item#*--visual=}" ;; '--return='*) option_return="${item#*--return=}" ;; '--no-hints'* | '--hints'*) - option_hints="$(get-flag-value hints --missing="$option_hints" -- "$item" | echo-affirmative --stdin)" + option_hints="$(get-flag-value --affirmative --fallback="$option_hints" -- "$item")" ;; '--no-label'* | '--label'*) - option_label="$(get-flag-value label --missing="$option_label" -- "$item")" + option_label="$(get-flag-value --fallback="$option_label" -- "$item")" ;; '--no-multi'* | '--multi'*) - option_multi="$(get-flag-value multi --missing="$option_multi" -- "$item" | echo-affirmative --stdin)" + option_multi="$(get-flag-value --affirmative --fallback="$option_multi" -- "$item")" ;; '--no-required'* | '--required'*) - option_required="$(get-flag-value required --missing="$option_required" -- "$item" | echo-affirmative --stdin)" + option_required="$(get-flag-value --affirmative --fallback="$option_required" -- "$item")" ;; '--no-confirm'* | '--confirm'*) - option_confirm="$(get-flag-value confirm --missing="$option_confirm" -- "$item" | echo-affirmative --stdin)" + option_confirm="$(get-flag-value --affirmative --fallback="$option_confirm" -- "$item")" ;; '--') items+=("$@") @@ -182,11 +182,11 @@ function choose_option() ( # check user configuration has no mistakes if test "${#items[@]}" -eq 0; then - help 'No s were provided.' - elif is-array-partial "${items[@]}"; then - help 'Invalid s were provided:' $'\n' "$(echo-verbose -- "${items[@]}")" + help 'No s provided.' + elif is-array-partial -- "${items[@]}"; then + help 'Invalid s provided:' $'\n' "$(echo-verbose -- "${items[@]}")" fi - if test "$option_label" != 'no' && is-odd "${#items[@]}"; then + if test "$option_label" != 'no' && is-odd -- "${#items[@]}"; then { echo-style --colors="$use_colors" --error="The amount of