Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ask, choose, confirm: implement #99, #213, #188 #229

Merged
merged 41 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
89b386e
ask: support `--default=<value>`, close #99 (#213)
balupton Feb 22, 2024
ffe2193
ask: integrate #99 (#213)
balupton Feb 25, 2024
69c5408
ask: support editing the default value
balupton Nov 11, 2023
8319266
ask: as read now supports defaults, redo the confirm flow
balupton Nov 11, 2023
2cea4c4
ask: use cursor rather than alt tty, implement --linger
balupton Nov 11, 2023
9dd6c88
choose-option/choose-menu merged into choose
balupton Apr 25, 2024
d332953
ask, choose, confirm: --confirm*, --linger, --question
balupton May 1, 2024
54d38bf
Merge commit 'ffe2193537c97430fb3ddf8a4bd5e0830909cac9' into dev-defa…
balupton May 27, 2024
a0f9658
better paging support for #188
balupton Jun 8, 2024
0bfea5d
choose: confirm paging implemented
balupton Jun 11, 2024
80aae98
choose: implement new paging, styling, and confirm
balupton Jun 12, 2024
4f20a2b
choose: show paging headers where paging is supported, not just when …
balupton Jun 12, 2024
e4d0c93
choose: improve and simplify the changing of menu modes
balupton Jun 12, 2024
1b3b67f
choose: add cancel menu
balupton Jun 12, 2024
788e0c9
choose: implement visible bar, reset confirm/cancel cursor
balupton Jun 12, 2024
787ad90
choose: clear and render in same operation
molleweide Jun 14, 2024
0fa17d8
Merge branch 'master' into dev-defaults
balupton Jun 28, 2024
e0670ed
choose: implement light theme compat /ref #188
balupton Jun 28, 2024
2982177
echo-style: merge `echo-element`, `echo-segment`
balupton Jul 1, 2024
3385c3f
choose: implement bell for invalid action
balupton Jul 1, 2024
835fbdf
choose: fix known bugs
balupton Jul 27, 2024
3eacc9c
echo-element, echo-segment: relocate to beta
balupton Jul 27, 2024
bde44a2
styling.md: update for `echo-style` inlining `echo-segment` and `echo…
balupton Jul 27, 2024
881aaef
dorothy: attempt fixing branch tests
balupton Jul 27, 2024
f6c4822
choose: fix linting issues
balupton Jul 27, 2024
2eeefcd
ask,choose,confirm: consistent styling
balupton Aug 6, 2024
d749adf
choose: test fixes
balupton Aug 7, 2024
0a500d2
choose: enable all tests, and fix regressions
balupton Aug 7, 2024
534e42d
ask: fixed failed tests
balupton Aug 7, 2024
aa2785f
echo-style, styles.bash: fix tests on old bash
balupton Aug 7, 2024
d513c42
choose, config-helper: increase CI test sleeps
balupton Aug 7, 2024
eb69b1a
read-key: fix bash v3 compat for page-[up/down]
balupton Aug 7, 2024
13fe93d
choose: add --skip-default tests
balupton Aug 7, 2024
bc65b45
read-key: fix more bash v3 special keys
balupton Aug 7, 2024
4795d94
fetch, setup-util-1password*: fixes
balupton Aug 7, 2024
314b26a
Merge branch 'master' into dev-defaults
balupton Aug 7, 2024
a28baea
choose, config-helper, dorothy: fix flakey tests
balupton Aug 7, 2024
44b0b69
ci: adjustments
BevryMe Aug 7, 2024
dca119a
environment.*: env crashes detected, close #235
balupton Aug 7, 2024
84df70a
choose, config-helper, dorothy: fix flakey tests
balupton Aug 7, 2024
fa4fe01
setup-python: fix pipx errors
balupton Aug 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/dorothy-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # prevent rate limiting
run: |
# ensure dorothy is cloned, and run command
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/install?slug=${{ github.repository }}&commit=${{ github.sha }}')"
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/install?slug=${{ github.repository }}&commit=${{ github.event.pull_request.head.sha || github.sha }}')"
- name: 'Dorothy Configure'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # prevent rate limiting
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # prevent rate limiting
run: |
# ensure dorothy is cloned, and run command
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/run?slug=${{ github.repository }}&commit=${{ github.sha }}')" -- dorothy test
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/run?slug=${{ github.repository }}&commit=${{ github.event.pull_request.head.sha || github.sha }}')" -- dorothy test
fresh-macos-test:
strategy:
fail-fast: false
Expand All @@ -140,7 +140,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # prevent rate limiting
run: |
# ensure dorothy is cloned, and run command
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/run?slug=${{ github.repository }}&commit=${{ github.sha }}')" -- dorothy test
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/run?slug=${{ github.repository }}&commit=${{ github.event.pull_request.head.sha || github.sha }}')" -- dorothy test
container-test:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -211,4 +211,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # prevent rate limiting
run: |
# ensure dorothy is cloned, and run command
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/run?slug=${{ github.repository }}&commit=${{ github.sha }}')" -- dorothy test
bash -c "$(curl -fsSL 'https://dorothy.bevry.me/run?slug=${{ github.repository }}&commit=${{ github.event.pull_request.head.sha || github.sha }}')" -- dorothy test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ Stable commands:

- [`bash.bash`](https://github.com/bevry/dorothy/tree/master/sourcces/bash.bash) for a Bash strict mode that actually works, and various shims/polyfills
- [`ask`](https://github.com/bevry/dorothy/tree/master/commands/ask), [`confirm`](https://github.com/bevry/dorothy/tree/master/commands/confirm), and [`choose`](https://github.com/bevry/dorothy/tree/master/commands/choose) for prompting the user for input
- [`echo-style`](https://github.com/bevry/dorothy/tree/master/commands/echo-style), [`echo-segment`](https://github.com/bevry/dorothy/tree/master/commands/echo-segment), [`echo-element`](https://github.com/bevry/dorothy/tree/master/commands/echo-element), [`echo-error`](https://github.com/bevry/dorothy/tree/master/commands/echo-error), [`echo-verbose`](https://github.com/bevry/dorothy/tree/master/commands/echo-verbose), and [`eval-helper`](https://github.com/bevry/dorothy/tree/master/commands/eval-helper) for output styling
- [`echo-style`](https://github.com/bevry/dorothy/tree/master/commands/echo-style), [`echo-error`](https://github.com/bevry/dorothy/tree/master/commands/echo-error), [`echo-verbose`](https://github.com/bevry/dorothy/tree/master/commands/echo-verbose), and [`eval-helper`](https://github.com/bevry/dorothy/tree/master/commands/eval-helper) for output styling
- Dozens of `echo-*`, `fs-*`, `get-*`, and `is-*` helpers

Beta commands:
Expand Down
11 changes: 11 additions & 0 deletions commands.beta/choose-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

function choose_menu() (
# b/c alias for choose
choose --index "$@"
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
choose_menu "$@"
fi
11 changes: 11 additions & 0 deletions commands.beta/choose-option
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

function choose_option() (
# b/c alias for choose
choose "$@"
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
choose_option "$@"
fi
19 changes: 8 additions & 11 deletions commands/echo-element → commands.beta/echo-element
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function echo_element() (
function help {
cat <<-EOF >/dev/stderr
ABOUT:
Forward <input> to [echo-style], with expansions for --open, --close, --openclose, and --status.
[echo-style] now natively supports elements, change [--open=] to [--element=], [--close=] to [--/element=], and [--openclose=] to [--element/=], and [--status=] remains the same.

USAGE:
echo-element [--] ...<input>
Expand All @@ -25,23 +25,20 @@ function echo_element() (
case "$item" in
'--help' | '-h') help ;;
'--open='*)
option_args+=('--element_open' "--bold=${item#*=}" '--element_close')
item="${item#*=}"
option_args+=("--element=$item")
;;
'--close='*)
option_args+=('--element_slash_open' "--bold=${item#*=}" '--element_close')
item="${item#*=}"
option_args+=("--/element=$item")
;;
'--openclose='*)
option_args+=('--element_open' "--bold=${item#*=}" '--element_slash_close')
item="${item#*=}"
option_args+=("--element/=$item")
;;
'--status='*)
item="${item#*=}"
if test "$item" -eq 0; then
# success
option_args+=("--g3=[$item]")
else
# failure
option_args+=("--e3=[$item]")
fi
option_args+=("--status=$item")
;;
*) option_args+=("$item") ;;
esac
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/echo-exit-status
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function echo_exit_status() (

local cmd_status
eval_capture --statusvar=cmd_status -- "${cmd[@]}"
print_line "$cmd_status"
__print_line "$cmd_status"
)

# fire if invoked standalone
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/echo-if-directory
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function echo_if_directory() (

function on_input {
if test -n "$1" -a -d "$1"; then
print_line "$1"
__print_line "$1"
fi
}

Expand Down
4 changes: 2 additions & 2 deletions commands.beta/echo-if-empty
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ function echo_if_empty() (
}
function on_finish {
if is-empty-string -- "$inputs"; then
print_string "$fallback"
__print_string "$fallback"
else
print_string "$inputs"
__print_string "$inputs"
fi
}
stdinargs "${option_args[@]}"
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/echo-if-executable
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function echo_if_executable() (

function on_input {
if test -n "$1" -a -x "$1"; then
print_line "$1"
__print_line "$1"
fi
}

Expand Down
2 changes: 1 addition & 1 deletion commands.beta/echo-if-path
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function echo_if_path() (

function on_input {
if is-present -- "$1"; then
print_line "$1"
__print_line "$1"
fi
}

Expand Down
2 changes: 1 addition & 1 deletion commands.beta/echo-nonflags
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function echo_nonflags() (

function on_input {
if [[ $1 != -* ]]; then
print_line "$1"
__print_line "$1"
fi
}

Expand Down
2 changes: 1 addition & 1 deletion commands.beta/echo-numeric
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function echo_numeric() (
local had_an_invalid_input=no
function on_input {
if is-number -- "$1"; then
print_line "$1"
__print_line "$1"
else
echo-style --error="[$1] is not a number" >/dev/stderr
had_an_invalid_input=yes
Expand Down
29 changes: 29 additions & 0 deletions commands.beta/echo-segment
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

function echo_segment() (
source "$DOROTHY/sources/bash.bash"

# =====================================
# Arguments

function help {
cat <<-EOF >/dev/stderr
ABOUT:
[echo-style] now supports _open and _close segments natively, as such there is no need for [echo-segment] anymore

USAGE:
echo-segment [--] ...<input>
EOF
return 22 # EINVAL 22 Invalid argument
}

# =====================================
# Action

echo-style "$@"
)

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
echo_segment "$@"
fi
2 changes: 1 addition & 1 deletion commands.beta/echo-values
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function echo_values() (

function on_input {
if is-value -- "$1"; then
print_line "$1"
__print_line "$1"
fi
}

Expand Down
6 changes: 3 additions & 3 deletions commands.beta/edit-dns
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ function edit_dns() (
# edit /etc/resolv.conf

if get-app --quiet -- 'ProtonVPN'; then
print_line 'ProtonVPN enforces its own DNS'
__print_line 'ProtonVPN enforces its own DNS'
elif command-exists dnscrypt-proxy; then
print_line 'Editing DNS configuration of dnscrypt-proxy'
__print_line 'Editing DNS configuration of dnscrypt-proxy'
edit --wait -- "${HOMEBREW_PREFIX:-"/usr/local"}/etc/dnscrypt-proxy.toml"
else
print_line 'DNS editing only supported for dnscrypt-proxy'
__print_line 'DNS editing only supported for dnscrypt-proxy'
fi
)

Expand Down
12 changes: 6 additions & 6 deletions commands.beta/eject-all
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,23 @@ function eject_all() (
# =====================================
# Action

echo-segment --h1='eject-all'
echo-style --h1='eject-all'

echo-segment --h2='before'
echo-style --h2='before'
ls /Volumes
echo-segment --g2='before'
echo-style --g2='before'

eval-helper --quiet \
--pending="$(echo-style --bold='Ejecting...')" \
--success="$(echo-style --success='Ejected.')" \
--failure="$(echo-style --error='Failed to eject.')" \
-- osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'

echo-segment --h2='after'
echo-style --h2='after'
ls /Volumes
echo-segment --g2='after'
echo-style --g2='after'

echo-segment --h1='eject-all'
echo-style --h1='eject-all'
)

# fire if invoked standalone
Expand Down
8 changes: 4 additions & 4 deletions commands.beta/ensure-trailing-slash
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ function ensure_trailing_slash() (
for path in "${option_paths[@]}"; do
if test -d "$path"; then
if [[ $path != */ ]]; then
print_line "$path/"
__print_line "$path/"
else
print_line "$path"
__print_line "$path"
fi
elif test -f "$path"; then
if [[ $path == */ ]]; then
length="${#path}"
print_line "${path:0:length-1}"
__print_line "${path:0:length-1}"
else
print_line "$path"
__print_line "$path"
fi
else
echo-style --error='Not a file nor directory:' ' ' --code="$path" >/dev/stderr
Expand Down
8 changes: 4 additions & 4 deletions commands.beta/get-git-default-branch
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ function get_git_default_branch() (
default_global="$(git config --global init.defaultBranch 2>/dev/null || :)"

if test -n "$default_local" && __branch_exists "$default_local"; then
print_line "$default_local"
__print_line "$default_local"
elif test -n "$default_global" && __branch_exists "$default_global"; then
print_line "$default_global"
__print_line "$default_global"
elif __branch_exists 'main'; then
print_line 'main'
__print_line 'main'
elif __branch_exists 'master'; then
print_line 'master'
__print_line 'master'
else
echo-error 'Unable to determine the default branch.'
return 1
Expand Down
6 changes: 3 additions & 3 deletions commands.beta/icloud-helper
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ function icloud_helper() (
# .screenflow does not play niceley with iCloud Drive, as it is a secret directory
if test ! -d "$path" && [[ $path != *".DS_Store" && $path != *".icloud" ]]; then
if [[ $path == *".screenflow"* || $path == *".sketch"* ]]; then
print_line "skipped $path, as it is a directory in disguise as a file, and can only evict files"
__print_line "skipped $path, as it is a directory in disguise as a file, and can only evict files"
else
brctl evict "$path"
fi
else
print_line "skipped $path, as it is a directory or excluded path"
__print_line "skipped $path, as it is a directory or excluded path"
fi
done
}
Expand All @@ -103,7 +103,7 @@ function icloud_helper() (
if test "$(type -t "$action")" = 'function'; then
"$action" "${option_args[@]}"
else
print_line "Action [$action] not yet implemented." >/dev/stderr
__print_line "Action [$action] not yet implemented." >/dev/stderr
return 78 # ENOSYS 78 Function not implemented
fi
)
Expand Down
20 changes: 10 additions & 10 deletions commands.beta/itunes-owners
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,29 @@ function itunes_owners() (
owner_list="$(fs-temp --directory='itunes-owners' --file='owner.txt' --touch)"
missing_list="$(fs-temp --directory='itunes-owners' --file='missing.txt' --touch)"
database="$HOME/Music/iTunes/iTunes Music Library.xml"
echo-style --h2="Reading $database"
echo-style --header2="Reading $database"

# fetch songs
local song_count=0
function fetch_songs {
echo-style --h2="Fetching songs to $song_list"
echo-style --header2="Fetching songs to $song_list"
rg --only-matching --regexp='<string>file://(.+)</string>' --replace='$1' <"$database" |
echo-url-decode --stdin |
echo-html-decode --stdin >"$song_list"
song_count="$(wc -l <"$song_list" | xargs)"
echo-style --g2="...found $song_count media files."
echo-style --good2="...found $song_count media files."
}
fetch_songs # @todo use eval-helper

# fetch owners
function fetch_owners {
local song owner
echo-style --h2="Fetching owners to $owner_list"
echo-style --header2="Fetching owners to $owner_list"
while read -r song; do
# check
if test ! -f "$song"; then
echo-style "$song" ' ' --notice='is missing'
print_line "$song" >>"$missing_list"
__print_line "$song" >>"$missing_list"
continue
fi

Expand All @@ -90,18 +90,18 @@ function itunes_owners() (
# extract
local owners owner_count owned_count
owners="$(cut -f1 -s <"$owner_list" | sort | uniq)"
owner_count="$(print_line "$owners" | wc -l | xargs)"
owner_count="$(__print_line "$owners" | wc -l | xargs)"
owned_count="$(wc -l <"$owner_list" | xargs)"

echo-style --h2="$owner_count UNIQUE OWNERS:"
print_line "$owners"
echo-style --header2="$owner_count UNIQUE OWNERS:"
__print_line "$owners"
echo

echo-style --h2="$owned_count OWNED MEDIA:"
echo-style --header2="$owned_count OWNED MEDIA:"
sort <"$owner_list" | column -t -s $'\t'
echo

echo-style --h2="$(wc -l <"$missing_list" | xargs) MISSING MEDIA:"
echo-style --header2="$(wc -l <"$missing_list" | xargs) MISSING MEDIA:"
sort <"$missing_list"
echo
)
Expand Down
Loading