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: comprehensive support of TTY modes and capabilities #254

Merged
merged 51 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
7f91040
choose, echo-wrap, read-key: support no-TTY
balupton Oct 1, 2024
2c1b508
WIP: choose, confirm, read-key: improve no-TTY support
balupton Oct 5, 2024
c7f31b1
bash.bash: add common helpers for performance
balupton Oct 9, 2024
ba73e79
read-key: rejig some lines for internal clarity
balupton Oct 9, 2024
2582cdf
confirm: rejig color and no-color rendering
balupton Oct 9, 2024
1dbdd43
brew: fix duplication in error messages and improve styling
balupton Oct 9, 2024
2fc7757
echo-wait: rejig some logic for clarity
balupton Oct 10, 2024
47f29cb
dorothy: add `__eval_wrap` helper for debug clarity
balupton Oct 10, 2024
b60ef24
dorothy: rejig clone and update to all support slug/branch/reference/…
balupton Oct 10, 2024
ee11038
fix mistakes in WIP commits
balupton Oct 10, 2024
7b9d99c
read-key: turns out the all key is ctrl+a
balupton Oct 10, 2024
c48e182
command-(missing|working): fix bad commit
balupton Oct 10, 2024
4098286
confirm, read-key: linting
balupton Oct 10, 2024
7a3236c
setup-environment-commands: improve performance
balupton Oct 10, 2024
4193b8e
dorothy: fix bad remote_name automation
balupton Oct 10, 2024
64c9cf6
bash.bash: add `has_needles` helper for performance
balupton Oct 10, 2024
6b7f98a
choose: auto-select solo required item for git-helper use case
balupton Oct 10, 2024
e15cab8
choose: try to fix choose prompt question title not showing on CI
balupton Oct 11, 2024
8a4583b
bash.bash: linting
balupton Oct 11, 2024
c71c557
is-tty: add proc and -p tests
balupton Oct 11, 2024
5def66e
WIP: removed `tty.bash` for `get-terminal-*` commands
balupton Oct 14, 2024
acee8c9
dorothy, symlink-helper: fix alpine symlink failures
balupton Oct 15, 2024
06a2cae
dorothy, fs-realpath: realpath on alpine doesn't support options
balupton Oct 15, 2024
369ff92
dorothy, fs-realpath: readlink on alpine doesn't support needed options
balupton Oct 15, 2024
99ac325
dorothy, fs-realpath: move alpine's implementation to fallback
balupton Oct 15, 2024
a9a57f5
dorothy, fs-realpath: detect when alpine uses busybox or coreutils an…
balupton Oct 15, 2024
41de4c2
dorothy: install coreutils installed on alpine, remove `ps` dependency
balupton Oct 15, 2024
fc24131
echo-file: fix bat usage, all: improve styling
balupton Oct 15, 2024
f62bebd
eval-helper: fix undefined columns
balupton Oct 15, 2024
5405c39
choose and read-key bugfixes
balupton Oct 15, 2024
b4ef3c8
bash.bash: add `__substr` shim, fix for `cpr` and `echo-style`
balupton Oct 16, 2024
383e36a
don't output screen buffer styles if not supported
balupton Oct 16, 2024
648843c
`get-terminal-(alternative|title)-support` fixed
balupton Oct 16, 2024
598918e
style.bash: clear screen if alt buffer not available
balupton Oct 16, 2024
cc483c3
styles: newline and clear if alt screen buffer not supported
balupton Oct 16, 2024
888b090
styles: newline, clear, alt screen buffer adjustments for CI
balupton Oct 16, 2024
d99a9a6
add `dorothy-warnings`, a deprecation system
balupton Oct 23, 2024
a37639d
consistentcy for commands.deprecated
balupton Oct 17, 2024
a3ba02f
debug-network: add comment to avoid https://github.com/bevry/dorothy/…
balupton Oct 17, 2024
e8a0640
readme: list @balupton's github list of Dorothy User Configurations
balupton Oct 17, 2024
713322d
echo-clear-lines: prep for improvements
balupton Oct 17, 2024
8324b75
improvements to clearing, and resolve setup-util(-bash) edge case
balupton Oct 17, 2024
52958a2
shellcheck: ignore SC2016, it is always intentional
balupton Oct 21, 2024
099bb6b
ask/choose/confirm: complete no-TTY support
balupton Oct 23, 2024
0dfebda
ask/choose/confirm: fix broken tests, although `ask` test has a clear…
balupton Oct 23, 2024
613cec8
improvements to TTY and STDIN reporting
balupton Oct 25, 2024
d605711
ask: rewrote for new stdin/tty learnings, properly support no-TTY
balupton Oct 25, 2024
d2b29cb
use the correct quote/escape for the context
balupton Oct 25, 2024
36e8c75
Merge branch 'master' into dev/fix-253
balupton Oct 25, 2024
1c7b588
brew-installed: fix comment typos
balupton Oct 26, 2024
4f66b71
re-add `--needle=` prefix on needle option on `is-needle` calls, to p…
balupton Oct 26, 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
4 changes: 2 additions & 2 deletions commands/echo-mkdir → commands.beta/echo-mkdir
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ function echo_mkdir() (
# construct command
if test "$option_sudo" = 'yes'; then
function __mkdir {
sudo-helper --reason="Your sudo/root/login password is required to make the directory: $*" -- mkdir -p "$@"
sudo-helper --reason='Your sudo/root/login password is required to ensure the directory exists:' -- mkdir -p "$@"
}
else
function __mkdir {
mkdir -p
mkdir -p "$@"
}
fi

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function echo_nothing_or_fail() (
return 1 # failure
}

function on_on_lines {
function on_no_lines {
return 0 # success
}

Expand Down
2 changes: 1 addition & 1 deletion commands.beta/edit-dns
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function edit_dns() (

if get-app --quiet -- 'ProtonVPN'; then
__print_lines 'ProtonVPN enforces its own DNS'
elif command-exists -- dnscrypt-proxy; then
elif __command_exists -- dnscrypt-proxy; then
__print_lines 'Editing DNS configuration of dnscrypt-proxy'
edit --wait -- "${HOMEBREW_PREFIX:-"/usr/local"}/etc/dnscrypt-proxy.toml"
else
Expand Down
4 changes: 2 additions & 2 deletions commands.beta/get-codec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function get_codec_test() (
ogg_media_file="$(fs-temp --directory='get-codec' --file --extension='ogg')"
down --url="$ogg_media_url" --filepath="$ogg_media_file"

if command-exists -- ffprobe; then
if __command_exists -- ffprobe; then
eval-tester --name='ogg vorbis file is ogg vorbis' --stdout='vorbis' \
-- get-codec --path="$ogg_media_file"
else
Expand Down Expand Up @@ -69,7 +69,7 @@ function get_codec() (
# =====================================
# Action

if ! command-exists -- ffprobe; then
if __command_missing -- ffprobe; then
echo-error 'ffprobe is required for this command.'
return 6 # ENXIO 6 No such device or address
fi
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/is-yum
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function is_yum() (
# =====================================
# Action

command-exists -- yum
__command_exists -- yum
)

# fire if invoked standalone
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/macos-settings
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function macos_settings() (
# Global

if is-needle --needle=screenshotdir -- "${choices[@]}"; then
mkdir -p "$HOME/Desktop/Screenshots"
__mkdirp "$HOME/Desktop/Screenshots"
defaults write com.apple.screencapture location "$HOME/Desktop/Screenshots"
else
defaults delete com.apple.screencapture location &>/dev/null || :
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/macos-state
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function macos_state() (
}
function do_mkdir {
local path="$1"
mkdir -p "$(dirname "$path")"
__mkdirp "$(dirname "$path")"
}
function do_replace {
local path="$path"
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/pdf-decrypt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function pdf_decrypt() (
# =====================================
# Dependencies

if command-missing -- qpdf; then
if __command_missing -- qpdf; then
echo-style --error="[qpdf] is missing, install it first." >/dev/stderr
return 1
fi
Expand Down
14 changes: 7 additions & 7 deletions commands.beta/setup-server
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function setup_server() (
# ensure correct share user password
if test -n "$SHARE_PASSWORD"; then
printf '%s:%s\n' "$SHARE_USER" "$SHARE_PASSWORD" | sudo-helper -- chpasswd
if command-exists -- smbpasswd; then
if __command_exists -- smbpasswd; then
printf '%s\n%s\n' "$SHARE_PASSWORD" "$SHARE_PASSWORD" | sudo-helper -- smbpasswd -sa "$SHARE_USER"
fi
fi
Expand Down Expand Up @@ -430,7 +430,7 @@ function setup_server() (
}
function act_disconnect {
# shutdown and disable nord
if command-exists -- nordvpn; then
if __command_exists -- nordvpn; then
# stop vpn dependent
service-helper --ignore --stop -- "${services_vpn_dependent[@]}"

Expand Down Expand Up @@ -467,13 +467,13 @@ function setup_server() (
fi

# syncthing
if command-exists -- syncthing; then
if __command_exists -- syncthing; then
sudo ufw allow from 192.168.0.0/16 to any app syncthing || : # local syncthing peers
sudo ufw allow from 192.168.0.0/16 to any app syncthing-gui || : # local syncthing gui
fi

# transmission
if command-exists -- transmission-daemon; then
if __command_exists -- transmission-daemon; then
sudo ufw allow from 192.168.0.0/16 to any port 51413 # local transmission peers
sudo ufw allow from 192.168.0.0/16 to any port 9091 # local transmission gui
fi
Expand Down Expand Up @@ -508,7 +508,7 @@ function setup_server() (
fi

# continue with nordvpn
if command-exists -- nordvpn; then
if __command_exists -- nordvpn; then
# ensure correctly configured
setup-util-nordvpn --quiet || :

Expand Down Expand Up @@ -593,7 +593,7 @@ function setup_server() (
local ec

# no nordvpn on this machine, so just check the internet is working
if command-missing -- nordvpn; then
if __command_missing -- nordvpn; then
is-internet-working
return 0
fi
Expand Down Expand Up @@ -642,7 +642,7 @@ function setup_server() (
-- resolvectl dns
eval-helper --no-quiet --wrap \
-- nslookup cloudflare.com
if command-exists -- nordvpn; then
if __command_exists -- nordvpn; then
eval-helper --no-quiet --wrap \
-- nordvpn status
eval-helper --no-quiet --wrap \
Expand Down
2 changes: 1 addition & 1 deletion commands.beta/xps2pdf
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function xps2pdf_() (
echo-style --bold="Converting " --code="$xps" --bold=" to " --code="$pdf"
gxps -sDEVICE=pdfwrite -sOutputFile="$pdf" -dNOPAUSE "$xps"

if command-exists -- GetFileInfo SetFile; then
if __command_exists -- GetFileInfo SetFile; then
ctime="$(GetFileInfo -m "$xps")"
SetFile -d "$ctime" "$pdf"
fi
Expand Down
10 changes: 5 additions & 5 deletions commands.beta/ytd-helper
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,20 @@ function ytd_helper() (

# handle tool
if test -z "$tool"; then
if command-exists -- 'yt-dlp'; then
if __command_exists -- 'yt-dlp'; then
tool='yt-dlp'
elif command-exists -- 'youtube-dl'; then
elif __command_exists -- 'youtube-dl'; then
tool='youtube-dl'
else
get-installer --first-success --invoke --quiet -- ytd-dlp youtube-dl
if command-exists -- 'yt-dlp'; then
if __command_exists -- 'yt-dlp'; then
tool='yt-dlp'
elif command-exists -- 'youtube-dl'; then
elif __command_exists -- 'youtube-dl'; then
tool='youtube-dl'
fi
fi
fi
if test -z "$tool" || command-missing -- "$tool"; then
if test -z "$tool" || __command_missing -- "$tool"; then
echo-error "tool [$tool] is not available"
return 3 # ESRCH 3 No such process
fi
Expand Down
6 changes: 2 additions & 4 deletions commands/brew
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ function brew_() (
- disable brew environment hints, as Dorothy handles that better via [setup-environment-commands]
EOF
if test -z "$bin"; then
__print_line
echo-style --error='Homebrew is not installed.'
if is-mac; then
echo-style --error='Homebrew is not installed.' ' ' --notice='Install it with:' ' ' --code='setup-mac-brew'
echo-style --error1='Homebrew is not installed.' --notice1=' Install it with: ' --code-notice1='setup-mac-brew'
else
echo-style --error='Homebrew is not installed.'
echo-style --error1='Homebrew is not installed.'
fi
# ^ don't use get-installer, as bash v5 may not exist yet
return 74 # EPROGUNAVAIL 74 RPC prog. not avail
Expand Down
2 changes: 1 addition & 1 deletion commands/btrfs-helper
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function btrfs_helper() (
# =======================================================
# Dependencies

if command-missing -- btrfs; then
if __command_missing -- btrfs; then
setup-util-btrfs --quiet
fi

Expand Down
2 changes: 1 addition & 1 deletion commands/checksum
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function checksum_() (

local item algorithms=()
for item in 'md5sum' 'shasum' 'sha256sum'; do
if command-exists -- "$item"; then
if __command_exists -- "$item"; then
algorithms+=("$item")
fi
done
Expand Down
Loading
Loading