script-wizard
script-wizard is a shell script helper program to delegate the
responsibility of asking questions to the user, asking for
confirmation, making selections, etc. The normalized response is
printed to stdout for the script to consume.
This is a single binary application that utilizes the inquire library for providing a nicer user interface than the typical shell script is capable of.
Platforms
Pre-built binaries are available for:
| OS | Architecture |
|---|---|
| Linux | x86_64, aarch64 |
| Windows | x86_64, aarch64 |
| macOS | x86_64, aarch64 |
Install
Install with cargo
Install with Nix
Install from GitHub releases
Grab the latest release from GitHub or run this command to download and install automatically:
ARCHIVE=script-wizard--.tar.gz
Or, install with this curlbomb:
Examples in Bash
ask
Ask the user a question and capture the response:
# Set the alias to make it easier to use:
# Record the user's response into the NAME variable:
NAME=
confirm
Ask the user a yes/no question, with a prepared default response (eg.
yes is the default here):
# Set the alias to make it easier to use:
# Confirm returns an exit code: 0=yes 1=no :
if ; then
else
fi
# But maybe you want to record a literal "true" or "false" into a variable?:
LIKES_LINUX=
choose
Present a list of options to the user and have them select a single response from the list:
# Set the alias to make it easier to use:
CHOSEN=
# You can use an option from a bash array too:
options=("red" "blue" "greenish orange" "purple")
COLOR=
select
Present a list of options to the user and have them select multiple responses (zero or more) from the list:
# Use printf to print one per line (echo would merge into one line):
date
Present a date picker to the user:
# Pick a date between 2023/10/01 and 2023/10/20:
DATE=
editor
Present a full text editor entry to the user:
BIOGRAPHY=
Watch out: There is a potential bug here if your editor prints
anything to stdout. (In the case of emacsclient, it undesirably
captures the text "Waiting for Emacs...".) Using --json will wrap
the correct editor text in double quotes, and piping the output
through sed 's/^[^\"]*//' will remove the text before the first
double quote.
Set the common EDITOR environment variable to choose the editor it
launches.
menu
Present a menu of command entries that the user can select and
execute. The entries must be specified in the format: ENTRY = COMMAND where ENTRY is the text line of the menu entry, and
COMMAND is the shell command to run if the entry is selected:
Babashka pod
script-wizard can run as a Babashka
pod, providing a native Clojure API
for all commands (ask, confirm, choose, select, date, editor,
and menu):
(require '[babashka.pods :as pods])
(pods/load-pod ["script-wizard" "pod"])
(require '[pod.enigmacurry.script-wizard :as sw])
(sw/ask "What is your name?" :default "World")
(sw/confirm "Continue?" :default :yes)
(sw/choose "Pick one" ["a" "b" "c"])
Pod mode is entered automatically when stdin is not a TTY (i.e., when
input is piped), so you can also load the pod without the explicit
"pod" subcommand:
(pods/load-pod ["script-wizard"])
When stdin is a TTY and no subcommand is given, the help text is printed instead.
Common options
--json- the default is to print raw text even if it spans multiple lines. If you specify--jsonit will print it as compact JSON on a single line, splitting lines into lists of strings, or as a quoted string if its just supposed to be one line, depending on the subcommand.