Skip to content

Commit 88b49ef

Browse files
committed
huge WIP commit
- new `__do` and `__try`, instead of `eval_capture` - better coverage and tests, see `dorothy-internals` - more powerful API - new `is-fs` helpers - new `echo-wait` (maybe should rename to `echo-write`) - no longer needs sponge - more powerful API - moreutils as such is no longer a dorothy recommended dep - auto-sudo escalation on nearly everything - new sudo/elevate/elevated args - use FDs instead of device files where sensible to avoid linux divergence from macos - ... todo
1 parent 203df39 commit 88b49ef

File tree

429 files changed

+7412
-2920
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

429 files changed

+7412
-2920
lines changed

Diff for: TODOS.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# TODOS
2+
3+
ssh-helper
4+
until-success
5+
eval-helper
6+
eval-helper --terminal-device-file=/dev/stderr
7+
8+
is-\* --reason support
9+
10+
support --no-status and --status=no/null to discard status so failure returns 0
11+
12+
ensure-trailing-newline
13+
ensure-trailing-slash
14+
echo-file
15+
echo-wait
16+
config-helper
17+
18+
get-devices
19+
get-terminal-quiet-support could remove need for \__is_non_affirmative as it has eval_
20+
21+
debug-terminal-tty
22+
fs-dequarantine should use is-fs
23+
commands.test/bash.bash
24+
echo-style --tty

Diff for: commands.beta/convert-helper

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function convert_helper() (
4242
# Arguments
4343

4444
function help {
45-
cat <<-EOF >/dev/stderr
45+
cat <<-EOF >&2
4646
ABOUT:
4747
Covert a format into other formats.
4848

Diff for: commands.beta/echo-affirmative

+4-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function echo_affirmative() (
1010
# Arguments
1111

1212
function help {
13-
cat <<-EOF >/dev/stderr
13+
cat <<-EOF >&2
1414
ABOUT:
1515
For each <input>, output 'yes' if affirmative, 'no' if non-affirmative, otherwise note the invalidity to stderr.
1616
@@ -56,13 +56,14 @@ function echo_affirmative() (
5656
local had_invalid_input=no
5757
function on_input {
5858
local status
59-
eval_capture --statusvar=status -- is-affirmative -- "$1"
59+
# @todo source is-affirmative and call __is_affirmative instead
60+
__do --redirect-status={status} -- is-affirmative -- "$1"
6061
if [[ $status -eq 0 ]]; then
6162
__print_lines 'yes'
6263
elif [[ $status -eq 1 ]]; then
6364
__print_lines 'no'
6465
else
65-
echo-style --error="[$1] is neither affirmative or non-affirmative" >/dev/stderr
66+
echo-style --stderr --error="[$1] is neither affirmative or non-affirmative"
6667
had_invalid_input=yes
6768
fi
6869
}

Diff for: commands.beta/echo-escape-special

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function echo_escape_special() (
44
source "$DOROTHY/sources/stdinargs.bash"
55

66
function help {
7-
cat <<-EOF >/dev/stderr
7+
cat <<-EOF >&2
88
ABOUT:
99
For each input, output its escaped form.
1010

Diff for: commands.beta/echo-eval

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function echo_eval() (
1111
# Arguments
1212

1313
function help {
14-
cat <<-EOF >/dev/stderr
14+
cat <<-EOF >&2
1515
ABOUT:
1616
Execute the <command> on each stdin input.
1717

Diff for: commands.beta/echo-exit-affirmative

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function echo_exit_affirmative() (
99
# Arguments
1010

1111
function help {
12-
cat <<-EOF >/dev/stderr
12+
cat <<-EOF >&2
1313
ABOUT:
1414
Output the result of a command's exit status.
1515
@@ -63,7 +63,7 @@ function echo_exit_affirmative() (
6363
# Action
6464

6565
local cmd_status
66-
eval_capture --statusvar=cmd_status -- "${option_cmd[@]}"
66+
__try {cmd_status} -- "${option_cmd[@]}"
6767
if [[ $cmd_status -eq 0 ]]; then
6868
__print_lines 'yes'
6969
elif [[ $cmd_status -eq 1 ]]; then

Diff for: commands.beta/echo-exit-status

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function echo_exit_status() (
99
# Arguments
1010

1111
function help {
12-
cat <<-EOF >/dev/stderr
12+
cat <<-EOF >&2
1313
ABOUT:
1414
Given a command as arguments, execute it, output the exit status.
1515
@@ -49,7 +49,7 @@ function echo_exit_status() (
4949
# Action
5050

5151
local cmd_status
52-
eval_capture --statusvar=cmd_status -- "${cmd[@]}"
52+
__try {cmd_status} -- "${cmd[@]}"
5353
__print_lines "$cmd_status"
5454
)
5555

Diff for: commands.beta/echo-if-directory

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function echo_if_directory() (
5656
source "$DOROTHY/sources/stdinargs.bash"
5757

5858
function help {
59-
cat <<-EOF >/dev/stderr
59+
cat <<-EOF >&2
6060
ABOUT:
6161
Output <input>s that are a directory, or an unbroken symlink to a directory.
6262
Companion to [is-directory].

Diff for: commands.beta/echo-if-executable

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function echo_if_executable() (
5959
source "$DOROTHY/sources/stdinargs.bash"
6060

6161
function help {
62-
cat <<-EOF >/dev/stderr
62+
cat <<-EOF >&2
6363
ABOUT:
6464
Output <input>s that are paths that are executable (including that of symlinks, broken or otherwise).
6565
Companion to [is-executable].

Diff for: commands.beta/echo-mkdir

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function echo_mkdir() (
77
# Arguments
88

99
function help {
10-
cat <<-EOF >/dev/stderr
10+
cat <<-EOF >&2
1111
ABOUT:
1212
Make a directory at each input path, if it was not already one, and output its absolute path.
1313
@@ -64,7 +64,7 @@ function echo_mkdir() (
6464
# construct command
6565
if [[ $option_sudo == 'yes' ]]; then
6666
function __mkdir {
67-
sudo-helper --reason='Your sudo/root/login password is required to ensure the directory exists:' -- mkdir -p -- "$@"
67+
sudo-helper --reason='Your password is required to momentarily grant privileges to ensure the directory exists:' -- mkdir -p -- "$@"
6868
}
6969
else
7070
function __mkdir {

Diff for: commands.beta/echo-non-affirmative

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function echo_non_affirmative() (
1010
# Arguments
1111

1212
function help {
13-
cat <<-EOF >/dev/stderr
13+
cat <<-EOF >&2
1414
ABOUT:
1515
For each input, output 'yes' if non-affirmative, 'no' if affirmative, otherwise note the invalidity to stderr.
1616
Using [is-non-affirmative] for the validation.
@@ -57,13 +57,13 @@ function echo_non_affirmative() (
5757
local had_invalid_input=no
5858
function on_line {
5959
local non_affirmative_status
60-
eval_capture --statusvar=non_affirmative_status -- is-non-affirmative -- "$1"
60+
__try {non_affirmative_status} -- is-non-affirmative -- "$1"
6161
if [[ $non_affirmative_status -eq 0 ]]; then
6262
__print_lines 'yes'
6363
elif [[ $non_affirmative_status -eq 1 ]]; then
6464
__print_lines 'no'
6565
else
66-
echo-style --error="[$1] is neither affirmative or non-affirmative" >/dev/stderr
66+
echo-style --stderr --error="[$1] is neither affirmative or non-affirmative"
6767
had_invalid_input=yes
6868
fi
6969
}

Diff for: commands.beta/echo-nonflags

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function echo_nonflags() (
44
source "$DOROTHY/sources/stdinargs.bash"
55

66
function help {
7-
cat <<-EOF >/dev/stderr
7+
cat <<-EOF >&2
88
ABOUT:
99
Output all arguments that aren't flags.
1010

Diff for: commands.beta/echo-nothing-or-fail

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function echo_nothing_or_fail() (
77
# Arguments
88

99
function help {
10-
cat <<-EOF >/dev/stderr
10+
cat <<-EOF >&2
1111
ABOUT:
1212
If input is provided, fail.
1313
If no input was provided, success.

Diff for: commands.beta/echo-numeric

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function echo_numeric() (
55
source "$DOROTHY/sources/stdinargs.bash"
66

77
function help {
8-
cat <<-EOF >/dev/stderr
8+
cat <<-EOF >&2
99
ABOUT:
1010
Outputs inputs that are numbers, otherwise note their invalidity to stderr.
1111
Using [is-number] for the validation.
@@ -32,7 +32,7 @@ function echo_numeric() (
3232
[] is not a number
3333
# exit status: 1
3434
35-
echo-numeric -- 1 a '' 2> /dev/stderr || :
35+
echo-numeric -- 1 a '' 2>>/dev/stderr || :
3636
3737
1
3838
# exit status: 0, it was ignored due to || :
@@ -49,7 +49,7 @@ function echo_numeric() (
4949
if is-number -- "$1"; then
5050
__print_lines "$1"
5151
else
52-
echo-style --error="[$1] is not a number" >/dev/stderr
52+
echo-style --stderr --error="[$1] is not a number"
5353
had_an_invalid_input=yes
5454
fi
5555
}

Diff for: commands.beta/echo-revolving-screen

+7-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function echo_revolving_screen() (
77
# Arguments
88

99
function help {
10-
cat <<-EOF >/dev/stderr
10+
cat <<-EOF >&2
1111
ABOUT:
1212
Continuously clear the output of a command, showing only the latest output, then clearing it upon completion.
1313
@@ -59,14 +59,10 @@ function echo_revolving_screen() (
5959
if [[ -z $option_lines || -z $option_columns || $option_lines -le 0 || $option_columns -le 0 ]]; then
6060
cat
6161
else
62-
local terminal_device_file clear_screen
63-
terminal_device_file="$(get-terminal-device-file)"
64-
clear_screen=$'\e[H\e[J'
65-
66-
local input total_lines=0 status wrapped lines=0
62+
local clear_screen=$'\e[H\e[J' input total_lines=0 status wrapped lines=0
6763
while IFS= read -r input || [[ -n $input ]]; do
68-
eval_capture --statusvar=status --outputvar=wrapped \
69-
-- gfold --width="$option_columns" <<<"$input"
64+
__do --redirect-status={status} --redirect-output={wrapped} -- \
65+
gfold --width="$option_columns" <<<"$input"
7066
#-- echo-wrap --width="$option_columns" -- "$input"
7167
if [[ $status -ne 0 ]]; then
7268
echo-error "$wrapped"
@@ -82,16 +78,16 @@ function echo_revolving_screen() (
8278
__print_lines "${clear_screen}${wrapped}" | head -n "$option_lines"
8379
else
8480
# clear the screen
85-
__print_lines "${clear_screen}${wrapped}" >"$terminal_device_file"
81+
__do --redirect-stdout=tty -- __print_lines "${clear_screen}${wrapped}"
8682
fi
8783
total_lines="$lines"
8884
else
8985
# print the wrapped output
90-
__print_lines "$wrapped" >"$terminal_device_file"
86+
__do --redirect-stdout=tty -- __print_lines "$wrapped"
9187
fi
9288
done
9389
# we are now done, so clear wrapped
94-
__print_string "${clear_screen}" >"$terminal_device_file"
90+
__do --redirect-stdout=tty -- __print_string "${clear_screen}"
9591
fi
9692
)
9793

Diff for: commands.beta/echo-sort

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function echo_sort() (
44
source "$DOROTHY/sources/stdinargs.bash"
55

66
function help {
7-
cat <<-EOF >/dev/stderr
7+
cat <<-EOF >&2
88
ABOUT:
99
Sort the inputs using [sort]
1010

Diff for: commands.beta/echo-truncate-lines

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function echo_truncate_lines() (
3939
# Arguments
4040

4141
function help {
42-
cat <<-EOF >/dev/stderr
42+
cat <<-EOF >&2
4343
ABOUT:
4444
Truncate the <input> if it reaches more than <limit>.
4545

Diff for: commands.beta/echo-with-empty-fallback

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function echo_with_empty_fallback() (
44
source "$DOROTHY/sources/stdinargs.bash"
55

66
function help {
7-
cat <<-EOF >/dev/stderr
7+
cat <<-EOF >&2
88
ABOUT:
99
Output <fallback> if all <input> is zero-length.
1010
Similar to [echo-with-whitespace-fallback], [eval-on-empty-stdin], [eval-on-not-empty-stdin].

Diff for: commands.beta/echo-with-whitespace-fallback

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function echo_with_whitespace_fallback() (
44
source "$DOROTHY/sources/stdinargs.bash"
55

66
function help {
7-
cat <<-EOF >/dev/stderr
7+
cat <<-EOF >&2
88
ABOUT:
99
Output <fallback> if all <input> is only whitespace.
1010
Similar to [echo-with-empty-fallback].

Diff for: commands.beta/edit-dns

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function edit_dns() (
88
# Arguments
99

1010
function help {
11-
cat <<-EOF >/dev/stderr
11+
cat <<-EOF >&2
1212
ABOUT:
1313
If possible, edit the DNS configuration of the DNS service.
1414
You probably want [setup-dns] instead.

Diff for: commands.beta/edit-hosts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function edit_hosts() (
77
# Arguments
88

99
function help {
10-
cat <<-EOF >/dev/stderr
10+
cat <<-EOF >&2
1111
ABOUT:
1212
Edit the system's HOSTS file.
1313

Diff for: commands.beta/eject-all

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function eject_all() (
77
# Arguments
88

99
function help {
10-
cat <<-EOF >/dev/stderr
10+
cat <<-EOF >&2
1111
ABOUT:
1212
Eject all the ejectable drives attached to the system.
1313

0 commit comments

Comments
 (0)