chore: fix prompt input/output redirection to prevent interference with piped commands

Redirect all prompt output to stderr and read input directly from /dev/tty to ensure prompts work correctly when the script is piped or redirected.
This commit is contained in:
Jose B
2025-12-04 13:49:41 -05:00
parent 58444fd37f
commit 61e062fe1d

View File

@@ -87,25 +87,26 @@ prompt() {
fi fi
if [ "$is_secret" = true ]; then if [ "$is_secret" = true ]; then
echo -ne "${YELLOW}${prompt_text}: ${NC}" echo -ne "${YELLOW}${prompt_text}: ${NC}" >&2
value="" value=""
while IFS= read -r -s -n1 char; do while IFS= read -r -s -n1 char < /dev/tty; do
if [[ $char == $'\0' ]]; then if [[ $char == $'\0' ]]; then
break break
fi fi
if [[ $char == $'\177' ]] || [[ $char == $'\b' ]]; then if [[ $char == $'\177' ]] || [[ $char == $'\b' ]]; then
if [ ${#value} -gt 0 ]; then if [ ${#value} -gt 0 ]; then
value="${value%?}" value="${value%?}"
echo -ne "\b \b" echo -ne "\b \b" >&2
fi fi
else else
value+="$char" value+="$char"
echo -n "*" echo -n "*" >&2
fi fi
done done
echo "" echo "" >&2
else else
read -p "$(echo -e ${YELLOW}${prompt_text}: ${NC})" value echo -ne "${YELLOW}${prompt_text}: ${NC}" >&2
read value < /dev/tty
fi fi
if [ -z "$value" ] && [ -n "$default_value" ]; then if [ -z "$value" ] && [ -n "$default_value" ]; then