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:
13
setup.sh
13
setup.sh
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user