Skip to content

This is a very simple utility, intended for command line use, that accepts via command line or STDIN a set of data items, and then displays them, one per line, with checkboxes next to them, and the ability to move through them, selecting or deselecting them with the keyboard. When enter is pressed, the selected set it returned to STDOUT.

License

Notifications You must be signed in to change notification settings

wyhaines/selector.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Selector CI GitHub release GitHub commits since latest release (by SemVer)

selector

Selector implements a simple command line utility that takes a list of data items from the command line or STDIN (or both). Those elements are then displayed, one per line, with an empty checkbox next to it. The user can scroll through the list, selecting the items of interest. After completing that, pressing enter will return all of the selected elements on STDOUT.

The purpose of this utility is to provide a nice UI for operations where one wants to perform batch operations on some set of manually selected items. An example of this would be a utility that lists all git branches, and then deletes the selected branches. A sample implementation of this can be found in this gist.

Here's an example of that gist being used to clean up some old git branches:

visual-git-branch-rm-2.mp4

Installation

Download a prebuilt binary from Releases, or build from source.

To build from source, ensure that Crystal is installed on your OS: https://crystal-lang.org/install/

Clone this repository:

git clone https://github.com/wyhaines/selector.cr.git

Build the utility:

cd selector
shards build -p -s -t --release

The completed binary will be found at bin/selector.

Usage

Select some set of arguments passed on the command line:

selector a b c d e f g h i j | awk '{print "You selected " $0}'

If you selected a, e, and i, this would print You selected a e i.

Select from a list passed via STDIN:

/bin/ls | selector -d "\n" | xargs -l1 echo

This will output, one per line, the file names that are selected.

For command line help:

selector -h
❯ selector -h
  Usage: selector [options] [items...]

  selector displays everything passed on the command line (other than valid arguments), as well as all lines that are passed on STDIN,
  on-screen with a simple text based UI to scroll through them, selecting some subset. The subset that is selected will be returned on STDOUT.

  Use the up and down arrows to move through the list.
  Press SPACE or 'x' to toggle the selected status of an item.
  Press 'q' to discard all selections and exit.
  Press ENTER to accept all selections.

    -d DELIMITER, --delimiter=DELIMITER
                               Specify output delimiter
    -i DELIMITER, --input-delimiter=DELIMITER
                               Specify input delimiter for STDIN (default: newline)
    -v, --version              Show the selector version (v1.0.0)
    -h, --help                 Show this help

Contributing

  1. Fork it (https://github.com/wyhaines/selector/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

About

This is a very simple utility, intended for command line use, that accepts via command line or STDIN a set of data items, and then displays them, one per line, with checkboxes next to them, and the ability to move through them, selecting or deselecting them with the keyboard. When enter is pressed, the selected set it returned to STDOUT.

Resources

License

Stars

Watchers

Forks

Packages

No packages published