diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2020-02-24 01:31:39 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2020-02-24 01:31:39 -0800 |
| commit | 865092c656af70bd5317513d8e0ed87fdc1c9acd (patch) | |
| tree | c4311c89b75322b4bb9d7f3547ff0534b935d68f /helpers/bbask | |
| parent | a8fd1743191bdb0a7453a2d90055e9dcc61a5ece (diff) | |
Major update: instead of defining all the helper functions as static
C-strings prefixed to commands (modified by the Makefile), the helper
functions are now standalone scripts in the helpers/ dir, which gets
added to "$PATH" when running bb.
Diffstat (limited to 'helpers/bbask')
| -rwxr-xr-x | helpers/bbask | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/helpers/bbask b/helpers/bbask new file mode 100755 index 0000000..ad446ec --- /dev/null +++ b/helpers/bbask @@ -0,0 +1,31 @@ +#!/bin/sh +# A simple user-input asker. Result is output to stdout. +# Usage: ask [-1] [prompt [initial query]] +if [ "$1" = '-1' ]; then + # Get one character of input + tput civis >/dev/tty; + printf '\033[1m%s\033[0m' "$2" >/dev/tty; + stty -icanon -echo >/dev/tty 2>/dev/tty; + if [ "$(uname)" = "Darwin" ]; then + read -n 1 REPLY </dev/tty >/dev/tty; + echo $REPLY + else + dd bs=1 count=1 2>/dev/null </dev/tty + fi + stty icanon echo >/dev/tty 2>/dev/tty + tput cvvis >/dev/tty +else + # Get a line of input + if command -v ask >/dev/null; then + ask --history=bb.hist --prompt="$(printf '%s\033[?25h' "$1")" --query="$2" + else + printf "\033[1m%s\033[0m" "$1" >/dev/tty + tput cvvis >/dev/tty + if [ "$(uname)" = "Darwin" ]; then + read -e REPLY </dev/tty >/dev/tty + else + read REPLY </dev/tty >/dev/tty + fi + echo $REPLY + fi +fi |
