yon
is a tool for interactive shells that simplifies prompting the user binary "yes or no"-questions.
It works with all POSIX compatible shells, such as sh
, bash
, zsh
and many more, and has no further dependencies.
Dowload the yon.sh file or clone this repository to a directory of your choice.
In any new terminal, where you want to use yon
, source yon.sh via
>$ source /path/to/yon.sh
Now you can call it by its name: yon
.
Try
>$ yon --help
to learn about all its features and how to use it or have a look at the examples below.
In order to make yon
available in all new terminals by default, add the above source command to your .bashrc
file:
# file $HOME/.bashrc
if [ -f /path/to/yon.sh ]; then
source /path/to/yon.sh
fi
- basic usage
>$ yon Yes or No? Yes or No? [y/n]: y >$ echo $? 0 >$ echo $YON y
- default answer
>$ yon --default=yes Yes or No? Yes or No? [Y/n]: >$ echo $? 0 >$ echo $YON y
- five second timeout
>$ yon --timeout=5 Yes or No? Yes or No? [y/n]: >$ echo $? 2
- three attempts
>$ yon --attempts=3 Yes or No? Yes or No? [y/n]: x Yes or No? [y/n]: ? Yes or No? [y/n]: * >$ echo $? 3
- custom return variable
>$ yon --return-variable=myvar Yes or No? Yes or No? [y/n]: y >$ echo $? 0 >$ echo $YON y >$ echo $myvar y
- three attempts with five second timeout, custom return variable and default answer, which is assumed on timeout
>$ yon --default=yes --timeout=5 --attempts=3 --return-variable=myvar --default-on-timeout -- Yes or No? Yes or No? [Y/n]: x Yes or No? [Y/n]: ? Yes or No? [Y/n]: >$ echo $? 0 >$ echo $YON y >$ echo $myvar y
yon
is licensed under the MIT License with Exception.
Please refer to the license file for further information.