Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cdrubin/bash_ui

respond to arrow keys for selections in bash scripts
https://github.com/cdrubin/bash_ui

bash ui

Last synced: 2 months ago
JSON representation

respond to arrow keys for selections in bash scripts

Awesome Lists containing this project

README

        

# bash_ui
Some helpful functions for making interactive bash scripts on Linux terminal respond to cursor keys for data entry.

(and now not dependent on tput from ncurses)

[_DOWNLOAD_](https://raw.githubusercontent.com/cdrubin/bash_ui/master/bash_ui.sh)

## _select_, _multi-select_ and _select value_

----------
### Example 1 (_select_):

Allow a user to select a path

```sh

source bash_ui.sh

CHOICES=`find . -maxdepth 1 -mindepth 1 -type d -printf '%f\n'`
choose_one

echo $CHOSEN

```

---------
### Example 2 (_select multiple_):

Ask user to select from a set of options

```sh

source bash_ui.sh

CHOICES=`find . -maxdepth 1 -mindepth 1 -type d -printf '%f\n'`
choose_multiple

echo $CHOSEN

```

---------
### Example 3 (_select_):

```sh

source bash_ui.sh

read -r -d '' CHOICES <&1 1>/dev/tty)
echo "Chosen home dir: $result"

```

----------
### Example 6 (_select multiple_)

```sh
#!/bin/bash

result=$(find /home -maxdepth 1 -mindepth 1 -type d -printf '%f\n' | ./shui multiple 2>&1 1>/dev/tty)
echo "Chosen home directories:"
echo "$result"

```

----------
### Example 7 (_select multiple from provided heredoc_)

```sh
#!/bin/bash

echo "Choose your favourite characters"
read -r -d '' CHOICES <<- EOS
Roger Ellison
Duiwel Dewet
Roger Rabbit
EOS

result=$(echo -e "$CHOICES" | ./shui 2>&1 1>/dev/tty)
```