fix: [y/N] is asked on the terminal, not on stdin

confirm() returned yes whenever stdin was not a tty, so `dotup < /dev/null` in
a terminal drew the picker on /dev/tty and then installed without asking. It
now opens /dev/tty the way cmd_pick does and reads the answer there; it
auto-approves only when no terminal exists at all. pty test plus a mutation
(ISSUE-9).
This commit is contained in:
bcherb2 committed 2026-11-18 02:13:00 -05:00
1 parent 91a1224a5e
commit f8b17a79d3
3 files changed
+47 -2

No files matched your search

+6 -2
View File
@@ -1681,9 +1681,13 @@ cmd_pick() {
confirm() {
[ "$ASSUME_YES" -eq 0 ] || return 0
[ -t 0 ] || return 0
# The same question cmd_pick asks, for the same reason (ISSUE-9): `[ -t 0 ]`
# was false for `dotup < /dev/null` in a terminal, so the picker drew on
# /dev/tty and then the install ran with no [y/N] at all. Auto-yes only
# when there is no terminal anywhere; otherwise ask on the terminal.
(exec 3</dev/tty) 2>/dev/null || return 0
printf '\n install? [y/N] ' >&2
a=''; IFS= read -r a || a=''
a=''; IFS= read -r a < /dev/tty || a=''
case $a in y|Y|yes|YES) return 0 ;; *) say " nothing installed."; return 1 ;; esac
}