logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

tty.sh (657B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. target="$(dirname "$0")/../cmd/tty"
  5. plans=3
  6. . "$(dirname "$0")/tap.sh"
  7. tty >/dev/null 2>/dev/null
  8. is_tty=$?
  9. out_devnull() {
  10. "$target" "$@" >/dev/null
  11. }
  12. case $is_tty in
  13. 0)
  14. t noargs '' "$(tty)
  15. "
  16. t_cmd out_devnull '' out_devnull
  17. ;;
  18. 1)
  19. t --exit=1 noargs '' 'not a tty
  20. '
  21. t_cmd --exit=1 out_devnull '' out_devnull
  22. ;;
  23. *)
  24. skip noargs "system tty exited with $?"
  25. skip out_devnull "system tty exited with $?"
  26. ;;
  27. esac
  28. in_devnull() {
  29. "$target" "$@" </dev/null
  30. }
  31. t_cmd --exit=1 in_devnull 'not a tty
  32. ' in_devnull