From cac2c153c2f1440acda64add9345ce05930a18fb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 10 Mar 2022 22:55:47 +0530 Subject: [PATCH] Fix #4809 --- shell-integration/ssh/bootstrap.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/shell-integration/ssh/bootstrap.sh b/shell-integration/ssh/bootstrap.sh index 67de4b93f..546e17429 100644 --- a/shell-integration/ssh/bootstrap.sh +++ b/shell-integration/ssh/bootstrap.sh @@ -112,10 +112,16 @@ else return $? } - if [ "$(printf "%s" "test" | command head -c 3 2> /dev/null)" = "tes" ]; then - # 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. + # 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 ghead -c 3 2> /dev/null)" = "tes" ]; then + # Some BSD based systems use ghead for GNU head which is strictly superior to + # Broken System Design head, so prefer it. + read_n_bytes_from_tty() { + command ghead -c "$1" < /dev/tty + } + elif [ "$(printf "%s" "test" | command head -c 3 2> /dev/null)" = "tes" ]; then read_n_bytes_from_tty() { command head -c "$1" < /dev/tty }