choice: a small console based menu selector, inspired by dmenu
choice
is a command-line application that displays an interactive menu to the
user. Like dmenu (a graphical menu), it
outputs the selected item to the standard output, so that the result can be
piped to another command.
Requirements
Tested on linux and macOS, doesn’t require any dependency to build.
Install
The general installation instructions can be followed to
install the program. It is packaged in our
Gentoo overlay as
app-misc/choice
.
You can clone the repository here.
Usage
choice
reads entries from stdin
and will output the selection in stdout
.
The user can filter displayed entries with the fuzzy search feature, by simply
typing the search text.
Type choice -h
for a list of option, alternatively, man choice
.
choice
can be used to wrap a number of commands and define convenient macros.
Some examples are provided in the choice
repository, see
example.sh.
In particular, one can grep for a symbol in a source code repository, pipe the
results into choice
so the user can choose a match, and open the corresponding
file at the corresponding line in a text editor. This is called vgrep
in the
example file. Another interesting application is to redefine bash’s history
navigation (ctrl+r) to use choice
, for a more convenient experience searching
the history. See the bind example in the examples file.
For more examples, checkout this blog post
choice
was created by syg, who had the idea of a command-line dmenu.
Originally it was a simple 50-lines bash script. Further features were added by
fxc and syg. It got eventually rewritten in C, to improve
performance for filtering the results when the search feature was used.
choice
is MIT-licensed.
Here is a demo gif: