2 # A simple user-input asker. Result is output to stdout.
3 # Usage: ask [-1] [prompt [initial query]]
4 if [ "$1" = '-1' ]; then
5 # Get one character of input
7 printf '\033[1m%s\033[0m' "$2" >/dev/tty;
8 stty -icanon -echo >/dev/tty 2>/dev/tty;
9 if [ "$(uname)" = "Darwin" ]; then
10 read -n 1 REPLY </dev/tty >/dev/tty;
13 dd bs=1 count=1 2>/dev/null </dev/tty
15 stty icanon echo >/dev/tty 2>/dev/tty
20 if command -v ask >/dev/null; then
21 ask --history=bb.hist --prompt="$(printf '%s\033[?25h' "$1")" --query="$2"
23 printf "\033[1m%s\033[0m" "$1" >/dev/tty
25 if [ "$(uname)" = "Darwin" ]; then
26 read -e REPLY </dev/tty >/dev/tty
28 read -r REPLY </dev/tty >/dev/tty