Features: 1) Add tty check for all interactive prompts to support non-interactive environments; 2) Provide fallback behavior for non-tty sessions.

Fixes: 1) Ensure prompts do not stall in non-interactive sessions.

Extra: 1) Minor adjustments to prompt messages for better clarity; 2) Refactor prompt logic for improved robustness.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-12-03 14:45:12 +03:00
parent a96aab33cb
commit d6e308a10f

View file

@ -8,8 +8,16 @@ get_random_hex() {
}
prompt_default() {
printf "Enter %s [%s]: " "$1" "$2"
read -r response
if [ -t 0 ]; then
printf "Enter %s [%s]: " "$1" "$2"
if read -r response </dev/tty; then
:
else
response=""
fi
else
response=""
fi
if [ -z "${response//[[:space:]]/}" ]; then
echo "$2"
else
@ -18,8 +26,16 @@ prompt_default() {
}
prompt_autogen() {
printf "Enter %s (leave blank to auto-generate): " "$1"
read -r response
if [ -t 0 ]; then
printf "Enter %s (leave blank to auto-generate): " "$1"
if read -r response </dev/tty; then
:
else
response=""
fi
else
response=""
fi
if [ -z "${response//[[:space:]]/}" ]; then
get_random_hex "$2"
else
@ -29,8 +45,12 @@ prompt_autogen() {
if [ -f .env ]; then
echo ".env already exists and will be overwritten." >&2
printf "Press Enter to continue or Ctrl+C to abort"
read -r
if [ -t 0 ]; then
printf "Press Enter to continue or Ctrl+C to abort: "
read -r _ </dev/tty || true
else
echo "Non-interactive session detected; proceeding without prompt." >&2
fi
fi
EVIBES_PROJECT_NAME=$(prompt_default EVIBES_PROJECT_NAME eVibes)