1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
#!/bin/bash
# Adapted from bits and pieces of /usr/bin/bug, to provide the functions
# that package says are permitted.
#
# /usr/bin/bug is:
# (C) 1996-2000 Christoph Lameter <clameter@debian.org>
# Nicolás Lichtmaier <nick@debian.org>
# Modifications:
# Copyright (C) 2000 Chris Lawrence <lawrencc@debian.org>
#
# You may freely redistribute, use and modify this software under the terms
# of the GNU General Public License.
set -e
# Wait for a keypress and put it in $KEY
getkey()
{
stty -icanon min 1 || true 2> /dev/null
KEY=$(dd bs=1 count=1 2> /dev/null)
stty icanon || true 2> /dev/null
KEY="${KEY:0:1}"
echo
}
export -f getkey
export YESNO="yYnN"
# Usage: yesno <prompt> "yep"|"nop" (<- default)
# output: REPLY
yesno()
{
while true; do
echo -n "$1"
getkey
# if 'n'
if [ "$KEY" = "${YESNO:2:1}" ] || [ "$KEY" = "${YESNO:3:1}" ]; then
REPLY=nop
return
fi
# if 'y'
if [ "$KEY" = "${YESNO:0:1}" ] || [ "$KEY" = "${YESNO:1:1}" ]; then
REPLY=yep
return
fi
# if \n
if [ "$KEY" = "" ]; then
REPLY=$2
return
fi
done
}
export -f yesno
#&>3
$1 3>|$2
|