Skip to content

joknarf/selector

Repository files navigation

Joknarf Tools Build and Release Packages Packages bash Licence

selector

Shell interactive menu (bash/zsh/ksh compatible)
Pure shell fzf-like

image image

image

features

  • dynamic interactive menu with items filtering / selection
  • optional description of items
  • customizable key interaction
  • browse directories and display file/folder/links icons (using left/right arrows to navigate in directories)
  • view/edit files (right arrow on file/F4 to edit)
  • browse archive files/view files in archives (recent lesspipe needed)
  • customizable colors/icons

demo

selector

install

Use a shell plugin manager like the famous thefly or use your favorite OS package manager with release packages

fly add joknarf/selector
or
brew install joknarf/tools/selector
dnf install https://github.com/joknarf/selector/releases/latest/download/selector.rpm
...

see joknarf tools for package repositories

usage

usage: selector [-p <prompt>] [-P <y|n>] [-k <keyfunc>] [-m <max>] [-o <opt>] -i <items>
       selector [-p <prompt>] [-P <y|n>] [-k <keyfunc>] [-m <max>] [-o <opt>] -f <itemfile>
args :
  -p, --prompt          <prompt> menu prompt
  -i, --items           <items> menu items \n separated [description \t separated]
  -f, --file            <file> file with items or - for stdin
  -F, --filter          <text> initial value of filter text (no initial filtering)
  -P, --powerline       <y|n>, powerline symbol usage
  -a, --autofilter      <y|n>, filter at keystrokes (default y)
  -k, --keyfunc         <keyfunc> Custom additional key function (using selector as function)
  -m, --max             <max> max number of items displayed
  -o, --option          <dirnames>|<filenames> render icons/browse
  -q, --quiet           silent selected item output

selector can be used as command line or sourced to be used as function (bash/zsh/ksh compatible)
When sourced, the selected item is available as $selected.

keys

key action
select next item
select prev item
End/ select last item
Home/ select first item
Shift/PgUp/CtlF next page
Shift/PgDn/CtlB previous page
Del/F8 delete item in menu
Esc exit
CtrlA use all screen to display menu
Tab apply/new filter
Enter validate item selected
Alti switch ignore case on/off
CtrlL refresh / resize menu according to term size
  • filter pattern can be applied entering text
  • selection can be done entering item number

when dirnames or filenames option, additional keys can be used:

key action
browse selected directory/view selected file
browse parent directory
Shift browse selected directory with subdirectories depth +1
Shift back to only show subdirectories depth 1
F4 edit file using EDITOR
F1 hide dotfiles

customize

selector menu can be customized setting following variables:

SELECTOR_FOLDER_ICON=🖿            # folder icon
SELECTOR_FILE_ICON=📄             # file icon
SELECTOR_CASEI=0                   # ignore case filter 0/1
SELECTOR_POWERLINE=y               # avoid using glyphs with 'n'
SELECTOR_COL_PROMPT="30;90;180"    # blue
SELECTOR_COL_TEXT="255;255;255"    # white
SELECTOR_COL_TOTAL="32;64;64"      # darkggrey
SELECTOR_COL_NUM="36;114;67"       # green
SELECTOR_COL_ARROW="41;98;114"     # cyan
SELECTOR_COL_ITEM="118;141;255"    # light blue
SELECTOR_COL_SELECTED="42;221;244" # light cyan

demo usage at:

  • shell-ng : bash/zsh/ksh shell next gen plugin, compilation including following plugins:
    • seedee : navigate in directories from command line with arrow keys with dir history (bash/zsh/ksh)
    • redo : replacement for CtrlR and Esc/ to search in command history (bash/zsh)
    • complete-ng : bash/zsh command line completion replacement for multiple choices output with interactive menu