diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index 5e5c99029..31158c6f6 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -94,12 +94,18 @@ else return $? } - read_n_bytes_from_tty() { - # using dd with bs=1 is very slow, so use head. On non GNU coreutils head - # does not limit itself to reading -c bytes only from the pipe so we can potentially lose - # some trailing data, for instance if the user starts typing. Cant be helped. - command head -c "$1" < /dev/tty - } + # using dd with bs=1 is very slow, so use head. On non GNU coreutils head + # does not limit itself to reading -c bytes only from the pipe so we can potentially lose + # some trailing data, for instance if the user starts typing. Cant be helped. + if [ "$(printf "%s" "test" | command head -c 3 2> /dev/null)" = "tes" ]; then + read_n_bytes_from_tty() { + command head -c "$1" < /dev/tty + } + else + read_n_bytes_from_tty() { + command dd bs=1 count="$1" < /dev/tty 2> /dev/null + } + fi fi debug() { dcs_to_kitty "print" "debug: $1"; }