You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

63 lines
1.1 KiB

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