Inquirer.js inspired prompts
Prompt for text
Prompt for text
# Raw input without validation
text=$(input "Please enter something and confirm with enter")
# Input with validation
text=$(with_validate 'input "Please enter at least one character and confirm with enter"' validate_present)
Show confirm dialog for yes/no
confirmed=$(confirm "Should it be?")
if [ "$confirmed" = "0" ]; then echo "No?"; else echo "Yes!"; fi
Renders a text based list of options that can be selected by the user using up, down and enter keys and returns the chosen option. Inspired by https://unix.stackexchange.com/questions/146570/arrow-key-enter-menu/415155#415155
options=("one" "two" "three" "four")
option=$(list "Select one item" "${options[@]}")
echo "Your choice: ${options[$option]}"
Render a text based list of options, where multiple can be selected by the user using up, down and enter keys and returns the chosen option. Inspired by https://unix.stackexchange.com/questions/146570/arrow-key-enter-menu/415155#415155
options=("one" "two" "three" "four")
checked=$(checkbox "Select one or more items" "${options[@]}")
echo "Your choices: ${checked}"
Show password prompt displaying stars for each password character letter typed it also allows deleting input
# Password prompt with custom validation
validate_password() { if [ ${#1} -lt 10 ];then echo "Password needs to be at least 10 characters"; exit 1; fi }
pass=$(with_validate 'password "Enter random password"' validate_password)
# Password ith no validation
pass=$(password "Enter password to use")
Open default editor ($EDITOR) if none is set falls back to vi
# Open default editor
text=$(editor "Please enter something in the editor")
echo -e "You wrote:\n${text}"
Evaluate prompt command with validation, this prompts the user for input till the validation function returns with 0
# Using builtin is present validator
text=$(with_validate 'input "Please enter something and confirm with enter"' validate_present)
# Using custom validator e.g. for password
validate_password() { if [ ${#1} -lt 10 ];then echo "Password needs to be at least 10 characters"; exit 1; fi }
pass=$(with_validate 'password "Enter random password"' validate_password)
Display a range dialog that can incremented and decremented using the arrow keys
# Range with negative min value
value=$(range -5 0 5)
Validate a prompt returned any value
# text input with validation
text=$(with_validate 'input "Please enter something and confirm with enter"' validate_present)