Debian Codegraph @

share/handle_bugscript

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