From 1c0a6cba403c9ad9fcd4bfe6a8672b1387226f41 Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Mon, 22 Jan 2024 18:08:29 +0800 Subject: [PATCH] modern conventions for all commands/ renames and deletions: - `is-quiet-enabled` renamed to `echo-quiet-enabled`, and new `is-quiet-enabled` is provided - `is-color-enabled` renamed to `echo-color-enabled`, and new `is-color-enabled` is provided - `is-desktop-session` deleted in favor of `is-headful` - `is-empty-size` moved to `commands.beta/` as it is faulty - `echo-trim-stdin` renamed to `echo-trim-padding`: support arguments - `echo-if-nonempty` renamed to `echo-trim-empty-lines` - `is-needles` deleted as `is-needle` now supports multiple needles - `is-values` deleted as `is-value` now supports multiple values - `echo-escape-regex(-replacement)?` renamed to `echo-escape-regexp(-replacement)?` - `expand-path-bash` deleted, inlined with `expand-path`, and noted case insensitivity inside `expand-path-zsh` - asset filter renamed to asset regexp, archive/build filter renamed to archive/build glob other actionable changes: - all applicable commands now support `--`, you should use it - get-flag-value now supports `--(non-)affirmative` flags, and optional name argument - setup-util/setup-util-*: use simpler `setup-util --check` for improving performance - stdinargs: - if `on_(arg|input)` are not provided, then support `on_(in)?line` for arguments - support `on_no_lines` - support `--max-args=` - note that this means empty arguments `''` will not be processed by `on_inline` and `on_line` handlers, this is expected and coincides with stdin behaviour - echo-(non-|exit-)?-affirmative/(echo|is)-(color|quiet)-enabled: return 91 on invalid values - echo-clear-lines/echo-revolving-door: reworked to solve issues with multline inputs, long inputs, and problematic cursor positions - fs-own: merged `--partial` and `--optional` into just `--optional`, optional now also ignores permission failures as expected, and improved performance notable changes: - all `commands/*` make use of dorothy argument conventions (including `--help` and `--` support) - consistent rg/grep arguments, using grep when using `--fixed-strings` - fix `=~` usage, it is a regular expression - echo-*: support help errors - is-*: add help, support dorothy argument conventions, support multiple arguments where applicable - (is|echo)-(color|quiet)-enabled: support `--fallback=` flag, and improved fallback/default handling - echo-exit-affirmative: support `--fallback=` - dorothy: when testing, output the unsafe function calls, and support running only specific tests - dorothy: when preparing, fixed creation of unnecessary nested symlinks other changes: - fix file permissions - `dorothy permissions`: fix non-performant file and directory permission fix - fix readme workflow badge - more consistent option parsing - contains-line: support arguments, support multiple needles - echo-clear-lines: support help and arguments - echo-count-lines: delegate to new stdinargs on_line handling, disable support for multiple arguments - added `echo-escape-command` - added `echo-escape-newlines` - echo-file: support argument lines - echo-filesnames: support argument lines - echo-if-command-exists: support argument lines - echo-if-file: support argument lines - echo-lines-after: support multiple needles - echo-lines-before: support multiple needles - echo-magnet-hash: support argument lines - echo-mkdir: support argument lines - echo-non-affirmative: support argument lines - echo-nothing-or-fail: support argument lines - echo-or-fail: support argument lines - echo-paths-and-basenames: support argument lines - echo-split: delegate to new stdinargs on_line handling, support multiple needles - echo-subpaths: support argument lines - echo-trim-each-line: add tests, support argument lines, fix it not actually working - echo-trim-special: support argument lines - echo-trim-zero-length: support argument lines - echo-url-decode: support argument lines - echo-url-encode: support argument lines - eval-helper/eval-tester: escape newlines in wrapping - expand-path-bash: fix variable leak - find-directories: support multiple paths - fs-*: support `--path=` flag - fs-size: remove faulty size check - get-app: support multiple apps - get-array: support `--size=` flag, verify size is integer - get-devices: fixed trimming - get-first-commit: add help, delegate to new git-helper methods, ensure GitHub CLI is installed - git-helper: add `first-commit`, `first-commit-hash`, `first-commit-url`, `github-slug` actions - is-admin: support help, support multiple users, support custom group, fix check on non-macos systems - is-affirmative: redo help - is-array-*: use `is-(non)?empty-string` checks - is-empty-string/is-nonempty-string: fixed documentation - is-generic: ignore case, add empty string, false, undefined, and null, as generics - is-match: support `--ignore-case` - added `is-non-affirmative` - setup-util-node: install Node 20 instead of 18 on APT - until-success: use `waiter` for better waiting message --- .editorconfig | 0 .github/FUNDING.yml | 0 .github/workflows/dorothy-workflow.yml | 0 .gitignore | 0 .trunk/configs/.markdownlint.yaml | 0 .trunk/configs/.prettierrc.yaml | 0 .trunk/configs/.shellcheckrc | 0 .trunk/configs/.yamllint.yaml | 0 .trunk/configs/eslint.config.js | 0 .trunk/configs/ruff.toml | 0 .trunk/trunk.yaml | 8 +- .vscode/extensions.json | 0 .vscode/settings.json | 0 .vscode/workspace.code-workspace | 0 CONTRIBUTING.md | 0 LICENSE.md | 0 README.md | 14 +- commands.beta/echo-escape-special | 3 + commands.beta/echo-if-directory | 3 + commands.beta/echo-if-empty | 97 +++++++++ commands.beta/echo-if-executable | 5 +- commands.beta/echo-if-path | 5 +- commands.beta/echo-nonflags | 3 + commands.beta/echo-numeric | 7 +- commands.beta/echo-on-empty-stdin | 66 ------ commands.beta/echo-sort | 3 + commands.beta/echo-values | 5 +- commands.beta/edit-dns | 2 +- commands.beta/ensure-trailing-newline | 12 +- commands.beta/ensure-trailing-slash | 12 +- commands.beta/example-generic-command | 2 +- commands.beta/get-codec | 4 +- commands.beta/icloud-helper | 6 +- commands.beta/is-empty-directory | 12 +- commands.beta/is-empty-size | 76 +++++++ commands.beta/is-even | 64 +++++- commands.beta/is-float | 2 +- commands.beta/is-needles | 40 ---- commands.beta/is-password-usable | 16 +- commands.beta/is-values | 19 -- commands.beta/itunes-owners | 4 +- commands.beta/mac-address-helper | 8 +- commands.beta/macos-settings | 46 ++-- commands.beta/macos-state | 6 +- commands.beta/mail-sync | 2 +- commands.beta/setup-server | 58 ++--- commands.beta/svg-export | 2 +- commands.beta/trim-audio | 2 +- commands.beta/twitter-helper | 6 +- commands.beta/video-merge | 2 +- commands.beta/xps2pdf | 12 +- commands/alias-helper | 6 +- commands/ask | 14 +- commands/brew | 7 +- commands/brew-installed | 6 +- commands/btrfs-helper | 6 +- commands/checksum | 30 +-- commands/choose-menu | 21 +- commands/choose-option | 28 +-- commands/choose-path | 10 +- commands/command-exists | 8 +- commands/command-missing | 10 +- commands/command-working | 8 +- commands/config-edit | 4 +- commands/config-helper | 114 +++++----- commands/contains-line | 77 ++++--- commands/cpr | 14 +- commands/date-helper | 26 +-- commands/dorothy | 200 ++++++++++-------- commands/dorothy-config | 9 +- commands/down | 38 ++-- commands/echo-affirmative | 27 ++- commands/echo-checksum | 11 +- commands/echo-clear-line | 21 +- commands/echo-clear-lines | 27 +-- commands/echo-color-enabled | 45 ++++ commands/echo-count-lines | 116 +++++----- commands/echo-element | 81 +++---- commands/echo-error | 34 ++- commands/echo-escape-command | 49 +++++ commands/echo-escape-newlines | 80 +++++++ .../{echo-escape-regex => echo-escape-regexp} | 27 ++- ...acement => echo-escape-regexp-replacement} | 21 +- commands/echo-escape-spaces | 9 + commands/echo-exit-affirmative | 36 ++-- commands/echo-file | 20 +- commands/echo-filenames | 11 +- commands/echo-first-line | 34 ++- commands/echo-fstab-decode | 9 + commands/echo-fstab-encode | 13 +- commands/echo-html-decode | 9 + commands/echo-html-encode | 9 + commands/echo-if-command-exists | 11 +- commands/echo-if-file | 11 +- commands/echo-if-nonempty | 48 ----- commands/echo-join | 25 +-- commands/echo-lines | 12 +- commands/echo-lines-after | 106 +++++++--- commands/echo-lines-before | 75 ++++--- commands/echo-lowercase | 9 + commands/echo-magnet-hash | 13 +- commands/echo-mkdir | 15 +- commands/echo-non-affirmative | 34 +-- commands/echo-nothing-or-fail | 15 +- commands/echo-or-fail | 16 +- commands/echo-paths-and-basenames | 12 +- commands/echo-quiet-enabled | 53 +++++ commands/echo-quote | 9 + commands/echo-revolving-door | 108 +++++++--- commands/echo-segment | 65 ++++-- commands/echo-split | 93 ++++++-- commands/echo-style | 4 +- commands/echo-subpaths | 11 +- commands/echo-title | 9 + commands/echo-trim-colors | 9 + commands/echo-trim-each-line | 47 +++- commands/echo-trim-empty-lines | 57 +++++ .../{echo-trim-stdin => echo-trim-padding} | 27 ++- commands/echo-trim-special | 13 +- commands/echo-trim-zero-length | 13 +- commands/echo-url-decode | 13 +- commands/echo-url-encode | 13 +- commands/echo-verbose | 9 + commands/echo-wait | 4 +- commands/edit | 24 +-- commands/eval-helper | 30 +-- commands/eval-tester | 28 +-- commands/expand-path | 71 ++++++- commands/expand-path-bash | 22 -- commands/expand-path-zsh | 7 +- commands/fetch | 4 +- commands/find-directories | 30 +-- commands/fs-absolute | 12 +- commands/fs-bytes | 13 +- commands/fs-dequarantine | 3 +- commands/fs-dirname | 13 +- commands/fs-extension | 13 +- commands/fs-filename | 17 +- commands/fs-join | 13 +- commands/fs-kilobytes | 13 +- commands/fs-megabytes | 11 +- commands/fs-own | 108 ++++------ commands/fs-realpath | 23 +- commands/fs-rm | 23 +- commands/fs-size | 18 +- commands/fs-speed | 17 +- commands/fs-structure | 17 +- commands/fs-temp | 8 +- commands/get-app | 142 +++++++------ commands/get-array | 22 +- commands/get-array-count | 19 +- commands/get-devices | 40 ++-- commands/get-filesystem | 10 +- commands/get-first-commit | 77 ++++++- commands/get-flag-value | 194 ++++++++++++----- commands/get-github-release | 4 +- commands/get-installer | 10 +- commands/get-local-to-remote | 16 +- commands/get-min | 14 +- commands/get-profile | 3 +- commands/get-python-version | 20 +- commands/get-size | 12 +- commands/get-terminal-theme | 2 +- commands/get-url-protocol | 12 +- commands/get-url-upgrade | 4 +- commands/get-user-id | 16 +- commands/get-volumes | 10 +- commands/git-helper | 122 +++++++---- commands/github-download | 67 +++--- commands/gocryptfs-helper | 14 +- commands/gpg-helper | 8 +- commands/gravatar | 16 +- commands/is-admin | 63 +++++- commands/is-affirmative | 39 ++-- commands/is-alpine | 38 +++- commands/is-apk | 36 ++++ commands/is-appimage | 36 ++++ commands/is-apple-silicon | 36 ++++ commands/is-apt | 36 ++++ commands/is-arch | 36 ++++ commands/is-array-count | 66 +++++- commands/is-array-count-ge | 66 +++++- commands/is-array-empty | 55 ++++- commands/is-array-empty-or-partial | 57 ++++- commands/is-array-full | 57 ++++- commands/is-array-full-or-partial | 55 ++++- commands/is-array-partial | 65 +++++- commands/is-bash-version-outdated | 12 +- commands/is-brew | 36 ++++ commands/is-btrfs | 25 ++- commands/is-ci | 4 + commands/is-color-enabled | 91 +++++--- commands/is-desktop-session | 23 -- commands/is-digit | 96 ++++++++- commands/is-dnf | 4 + commands/is-empty-ls | 59 +++++- commands/is-empty-size | 20 -- commands/is-empty-string | 56 +++-- commands/is-empty-value | 71 ++++++- commands/is-generic | 60 ++++-- commands/is-globstar | 59 +++++- commands/is-gnome | 36 ++++ commands/is-group | 23 +- commands/is-headful | 47 +++- commands/is-headless | 36 ++++ commands/is-integer | 80 +++++-- commands/is-internet-working | 20 +- commands/is-linux | 40 +++- commands/is-mac | 40 +++- commands/is-manjaro | 38 +++- commands/is-match | 16 +- commands/is-missing | 51 ++++- commands/is-needle | 77 ++++++- commands/is-non-affirmative | 87 ++++++++ commands/is-nonempty-string | 40 +++- commands/is-number | 111 +++++++--- commands/is-odd | 66 +++++- commands/is-opensuse | 38 +++- commands/is-present | 51 ++++- commands/is-quiet-enabled | 75 ++++--- commands/is-raspi | 36 ++++ commands/is-same | 16 +- commands/is-snap | 36 ++++ commands/is-ssh | 37 +++- commands/is-tty | 2 +- commands/is-ubuntu | 36 ++++ commands/is-user | 60 +++++- commands/is-user-in-group | 53 +++-- commands/is-value | 67 +++++- commands/is-vscode | 4 + commands/is-wsl | 36 ++++ commands/mount-helper | 18 +- commands/network-interface | 26 +-- commands/nvm-env | 28 +-- commands/open-app | 20 +- commands/openssl-helper | 6 +- commands/read-key | 17 +- commands/rm-junk | 38 ++-- commands/rm-modules | 38 ++-- commands/secret | 60 +++--- commands/service-helper | 116 +++++----- commands/set-hostname | 26 +-- commands/setup-bin | 2 +- commands/setup-dns | 67 +++--- commands/setup-git | 25 +-- commands/setup-go | 6 +- commands/setup-hosts | 10 +- commands/setup-linux-fonts | 39 +++- commands/setup-linux-recovery | 29 +++ commands/setup-linux-safegraphics | 35 ++- commands/setup-mac-appstore | 8 +- commands/setup-mac-brew | 22 +- commands/setup-node | 22 +- commands/setup-python | 6 +- commands/setup-ruby | 6 +- commands/setup-rust | 6 +- commands/setup-shell | 6 +- commands/setup-util | 152 +++++++------ commands/setup-util-1password-cli | 6 +- commands/setup-util-appimage | 9 +- commands/setup-util-apple-rosetta | 4 +- commands/setup-util-bandwhich | 6 +- commands/setup-util-bash | 8 +- commands/setup-util-bat | 6 +- commands/setup-util-bottom | 6 +- commands/setup-util-brew | 2 +- commands/setup-util-carapace | 6 +- commands/setup-util-cronitor | 6 +- commands/setup-util-delta | 6 +- commands/setup-util-deno | 8 +- commands/setup-util-docker | 4 +- commands/setup-util-dust | 6 +- commands/setup-util-elvish | 2 +- commands/setup-util-eza | 6 +- commands/setup-util-fd | 6 +- commands/setup-util-fzf | 6 +- commands/setup-util-gh | 6 +- commands/setup-util-git | 2 +- commands/setup-util-go | 2 +- commands/setup-util-gocryptfs | 8 +- commands/setup-util-golint | 4 +- commands/setup-util-got | 6 +- commands/setup-util-grex | 6 +- commands/setup-util-gum | 6 +- commands/setup-util-httpie | 2 +- commands/setup-util-hyperfine | 6 +- commands/setup-util-jq | 4 +- commands/setup-util-micro | 6 +- commands/setup-util-neovim | 4 +- commands/setup-util-node | 8 +- commands/setup-util-nu | 20 +- commands/setup-util-obs | 6 +- commands/setup-util-plex | 6 +- commands/setup-util-procs | 6 +- commands/setup-util-resilio | 2 +- commands/setup-util-ripgrep | 6 +- commands/setup-util-ruby | 2 +- commands/setup-util-rust | 2 +- commands/setup-util-sd | 6 +- commands/setup-util-shellcheck | 6 +- commands/setup-util-shfmt | 4 +- commands/setup-util-starship | 6 +- commands/setup-util-strongbox | 4 +- commands/setup-util-syncthing | 6 +- commands/setup-util-tea | 6 +- commands/setup-util-tealdeer | 4 +- commands/setup-util-teip | 6 +- commands/setup-util-tokei | 6 +- commands/setup-util-transmission | 4 +- commands/setup-util-vhs | 6 +- commands/setup-util-xcode | 20 +- commands/setup-util-xonsh | 2 +- commands/setup-util-zoxide | 6 +- commands/setup-utils | 30 +-- commands/sparse-vault | 52 ++--- commands/ssh-helper | 10 +- commands/sudo-helper | 60 +++--- commands/symlink-helper | 8 +- commands/together | 14 +- commands/until-success | 21 +- commands/unziptar | 60 +++--- commands/version-compare | 23 +- commands/waiter | 2 +- commands/what-is-listening | 10 +- commands/what-is-my-dns | 30 +-- commands/what-is-my-gateway | 4 +- commands/what-is-my-interface | 4 +- commands/what-is-my-ip | 20 +- commands/what-is-my-subnet | 2 +- commands/what-is-using | 12 +- config/autocomplete.sh | 0 config/dns.bash | 0 config/editors.bash | 0 config/environment.bash | 0 config/git.bash | 0 config/hosts.bash | 0 config/interactive.bash | 0 config/interactive.fish | 0 config/interactive.sh | 0 config/interactive.zsh | 0 config/profile.bash | 0 config/setup.bash | 0 config/shells.bash | 0 config/ssh.bash | 0 config/styles.bash | 8 +- config/theme.bash | 0 docs/bash/arrays.md | 20 +- docs/bash/builtins.md | 0 docs/bash/conditionals.md | 0 docs/bash/errors.md | 0 docs/bash/foreach-line.md | 0 docs/bash/parameter-expansions.md | 0 docs/bash/replace-inline.md | 2 +- docs/bash/resources.md | 0 docs/bash/subshells.md | 0 docs/bash/trailing-lines.md | 0 docs/bash/versions.md | 0 docs/dorothy/dorothy-not-loading.md | 0 docs/dorothy/manual-to-assisted.md | 0 docs/dorothy/private-configuration.md | 0 docs/scripting/commands.md | 0 docs/scripting/prompts.md | 0 docs/scripting/read-write-config.md | 0 docs/scripting/strict.md | 0 docs/scripting/styling.md | 2 +- init.fish | 0 init.sh | 0 package.json | 7 +- sources/autocomplete.fish | 0 sources/bash.bash | 0 sources/config.fish | 0 sources/config.sh | 0 sources/env.bash | 0 sources/environment.fish | 0 sources/environment.sh | 0 sources/history.fish | 0 sources/history.sh | 0 sources/interactive.fish | 0 sources/interactive.sh | 0 sources/login.fish | 0 sources/login.sh | 0 sources/nvm.sh | 0 sources/ripgrep.bash | 0 sources/shoutouts.txt | 1 - sources/ssh.fish | 0 sources/ssh.sh | 0 sources/stdinargs.bash | 155 ++++++++------ sources/theme.fish | 0 sources/theme.sh | 0 sources/tty.bash | 0 themes/demo.bash | 0 themes/demo.fish | 0 themes/demo.zsh | 0 themes/oz.bash | 0 themes/oz.fish | 0 themes/oz.zsh | 0 themes/starship.bash | 0 themes/starship.fish | 0 themes/starship.zsh | 0 399 files changed, 6036 insertions(+), 2692 deletions(-) mode change 100755 => 100644 .editorconfig mode change 100755 => 100644 .github/FUNDING.yml mode change 100755 => 100644 .github/workflows/dorothy-workflow.yml mode change 100755 => 100644 .gitignore mode change 100755 => 100644 .trunk/configs/.markdownlint.yaml mode change 100755 => 100644 .trunk/configs/.prettierrc.yaml mode change 100755 => 100644 .trunk/configs/.shellcheckrc mode change 100755 => 100644 .trunk/configs/.yamllint.yaml mode change 100755 => 100644 .trunk/configs/eslint.config.js mode change 100755 => 100644 .trunk/configs/ruff.toml mode change 100755 => 100644 .trunk/trunk.yaml mode change 100755 => 100644 .vscode/extensions.json mode change 100755 => 100644 .vscode/settings.json mode change 100755 => 100644 .vscode/workspace.code-workspace mode change 100755 => 100644 CONTRIBUTING.md mode change 100755 => 100644 LICENSE.md mode change 100755 => 100644 README.md create mode 100755 commands.beta/echo-if-empty delete mode 100755 commands.beta/echo-on-empty-stdin create mode 100755 commands.beta/is-empty-size delete mode 100755 commands.beta/is-needles delete mode 100755 commands.beta/is-values create mode 100755 commands/echo-color-enabled create mode 100755 commands/echo-escape-command create mode 100755 commands/echo-escape-newlines rename commands/{echo-escape-regex => echo-escape-regexp} (63%) rename commands/{echo-escape-regex-replacement => echo-escape-regexp-replacement} (62%) delete mode 100755 commands/echo-if-nonempty create mode 100755 commands/echo-quiet-enabled create mode 100755 commands/echo-trim-empty-lines rename commands/{echo-trim-stdin => echo-trim-padding} (62%) delete mode 100755 commands/expand-path-bash delete mode 100755 commands/is-desktop-session delete mode 100755 commands/is-empty-size create mode 100755 commands/is-non-affirmative mode change 100755 => 100644 config/autocomplete.sh mode change 100755 => 100644 config/dns.bash mode change 100755 => 100644 config/editors.bash mode change 100755 => 100644 config/environment.bash mode change 100755 => 100644 config/git.bash mode change 100755 => 100644 config/hosts.bash mode change 100755 => 100644 config/interactive.bash mode change 100755 => 100644 config/interactive.fish mode change 100755 => 100644 config/interactive.sh mode change 100755 => 100644 config/interactive.zsh mode change 100755 => 100644 config/profile.bash mode change 100755 => 100644 config/setup.bash mode change 100755 => 100644 config/shells.bash mode change 100755 => 100644 config/ssh.bash mode change 100755 => 100644 config/styles.bash mode change 100755 => 100644 config/theme.bash mode change 100755 => 100644 docs/bash/arrays.md mode change 100755 => 100644 docs/bash/builtins.md mode change 100755 => 100644 docs/bash/conditionals.md mode change 100755 => 100644 docs/bash/errors.md mode change 100755 => 100644 docs/bash/foreach-line.md mode change 100755 => 100644 docs/bash/parameter-expansions.md mode change 100755 => 100644 docs/bash/replace-inline.md mode change 100755 => 100644 docs/bash/resources.md mode change 100755 => 100644 docs/bash/subshells.md mode change 100755 => 100644 docs/bash/trailing-lines.md mode change 100755 => 100644 docs/bash/versions.md mode change 100755 => 100644 docs/dorothy/dorothy-not-loading.md mode change 100755 => 100644 docs/dorothy/manual-to-assisted.md mode change 100755 => 100644 docs/dorothy/private-configuration.md mode change 100755 => 100644 docs/scripting/commands.md mode change 100755 => 100644 docs/scripting/prompts.md mode change 100755 => 100644 docs/scripting/read-write-config.md mode change 100755 => 100644 docs/scripting/strict.md mode change 100755 => 100644 docs/scripting/styling.md mode change 100755 => 100644 init.fish mode change 100755 => 100644 init.sh mode change 100755 => 100644 package.json mode change 100755 => 100644 sources/autocomplete.fish mode change 100755 => 100644 sources/bash.bash mode change 100755 => 100644 sources/config.fish mode change 100755 => 100644 sources/config.sh mode change 100755 => 100644 sources/env.bash mode change 100755 => 100644 sources/environment.fish mode change 100755 => 100644 sources/environment.sh mode change 100755 => 100644 sources/history.fish mode change 100755 => 100644 sources/history.sh mode change 100755 => 100644 sources/interactive.fish mode change 100755 => 100644 sources/interactive.sh mode change 100755 => 100644 sources/login.fish mode change 100755 => 100644 sources/login.sh mode change 100755 => 100644 sources/nvm.sh mode change 100755 => 100644 sources/ripgrep.bash mode change 100755 => 100644 sources/ssh.fish mode change 100755 => 100644 sources/ssh.sh mode change 100755 => 100644 sources/stdinargs.bash mode change 100755 => 100644 sources/theme.fish mode change 100755 => 100644 sources/theme.sh mode change 100755 => 100644 sources/tty.bash mode change 100755 => 100644 themes/demo.bash mode change 100755 => 100644 themes/demo.fish mode change 100755 => 100644 themes/demo.zsh mode change 100755 => 100644 themes/oz.bash mode change 100755 => 100644 themes/oz.fish mode change 100755 => 100644 themes/oz.zsh mode change 100755 => 100644 themes/starship.bash mode change 100755 => 100644 themes/starship.fish mode change 100755 => 100644 themes/starship.zsh 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