stdin_exists() {
  # shellcheck disable=SC2312
  {
    ! [ -t 0 ] \
      && ! test "${NO_STDIN-}" = y `# for notty. e.g. notty xt vim ` \
      && ! test "$(readlink /proc/$$/fd/0)" = /dev/null \
      && ! test "$(readlink /proc/$$/fd/0)" = "$(readlink /proc/$$/fd/1)"
    # stdin may be redirected to the tty, but  will continue to say false (due to a bash bug)
    # so test to make sure 0 does not point to 1
  } >/dev/null 2>&1
}
# stdin_exists() {
#   ! [ -t 0 ] && read -t 0
# }
