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