#terminal-prompt #command-line #tool #confirm

app ask-yn

Terminal utility program to prompt the user to answer yes or no

5 unstable releases

Uses new Rust 2024

0.3.0 Dec 20, 2025
0.2.1 Dec 19, 2025
0.2.0 Dec 19, 2025
0.1.1 Nov 1, 2025
0.1.0 Oct 31, 2025

#2316 in Command line utilities

MIT license

6KB
68 lines

ask-yn

Terminal utility program to prompt the user to answer yes or no.

Example usage

Simplest Usage — No Default Argument

Without a default argument, the program with ask the user again if no input is given.

if ask-yn "Do a task?"; then
    echo "Doing a task"
else
    echo "Task canceled"
fi

The output in this case should look something like the following. Program output is in bold, user input is in italic:

Do a task? [y/n] maybe
Unrecognized response! Do a task? [y/n]
Unrecognized response! Do a task? [y/n] yes
Doing a task

With Default Argument

With a default argument, the program will use it when no input is provided.

if ask-yn "Do a task?" -d n; then
    echo "Doing a task"
else
    echo "Task canceled"
fi

The output in this case should look something like the following. Program output is in bold, user input is in italic:

Do a task? [y/N] maybe
Unrecognized response! Do a task? [y/N]
Task canceled

Invert Return code

The -i/--invert flag in this program inverts the return code. With this flag, the program will return a 1 when given a yes answer and a 0 otherwise.

if ask-yn "Don't do a task?" -i; then
    echo "Task canceled"
else
    echo "Doing a task"
fi

Dependencies

~1–1.5MB
~28K SLoC