Skip to content

pedro-hs/checkbox.sh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

93 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⌨️ checkbox.sh

Bash GitHub license

Interactive checkboxes (menu) with pagination and vim keybinds for bash



Table of Contents



Features

  • Select only a option or multiple options
  • Select or unselect multiple options easily
  • Select all or unselect all
  • Pagination
  • Optional Vim keybinds
  • A .sh file with approximately 500 lines
  • Start with options selected
  • Show selected options counter for multiple options
  • Show custom message
  • Show current option index and options amount
  • Copy current option value to clipboard
  • Help tab when press h or wrongly call the script

Quick Start

Run the script (in bash shell) with source checkbox.sh


Promotion

⭐ If you like this software, give a star ⭐

📖 Contributions are welcome 📖


Arguments Usage

Checkbox options

Use the argument --options=""


You can add new options:

  • With the character |
  • With new line
  • Mixed


To start with options selected, put + before the option text (in first character)

  • If the argument --multiple is missing, just the first option marked with + will start selected


Any of this ASCII signs \a \b \f \n \r \t in any part of options will be removed.


If --options"" is missing. Sample options will be loaded with 30 options.



Show message on header

Use the argument --message=""

You can customize message

  • Using ANSI
    Example: --message="\033[2K\033[31mhello world"

  • Using ASCII \a \b \e \f \n \r \t \v
    Example: --message="hello\rworld"

  • Maybe the layout breaks, in this case, try to refresh (press r)



Select multiple options

Use the argument --multiple



Return index instead of values

Use the argument --index



How to use with another script

You can get the script response in the variable $checkbox_output after execute the script

  • Example:
#!/usr/bin/env bash
source checkbox.sh --multiple --index
clear
selected_options="$checkbox_output"
echo "$selected_options"


Keybinds Usage

Move arround

Press [UP ARROW] or 'k' to move cursor to option above

Press [UP DOWN] or 'j' to move cursor to option below

Press [PAGE UP] or 'd' to move cursor 5 options above

Press [PAGE DOWN] or 'u' to move cursor 5 options below

Press [HOME] or 'g' to move cursor to first option

Press [END] or 'G' to move cursor to last option



Select current option

Press [SPACE] or x


Close and return selected options

Press [ENTER] or 'o'


Copy current option

Press 'c' or 'y'


Select or Unselect All (only with --multiple)

Press 'a' to select all and 'A' to unselect all


Select or Unselect Mode (only with --multiple)

Press 'v' to turn on/off select mode 'V' to turn on/off unselect mode

  • If select mode is on. Cursor will be green and when you move up or down the options will be selected

  • If unselect mode is on. Cursor will be red and when you move up or down the options will be unselected



Refresh

Press 'r' to refresh renderization



Help

Press 'h' or call script with invalid argument, and a help page will appear



Limitations

  • Doesn't have a good compatibility with mac, I will work on this in future
  • Uses bash array, so bash or similars are needed to run this script
  • Terminal must have at least 8 lines for the script works. Maybe breaks in some cases with --message too. Resize terminal and press 'r'
  • Don't have unit test