Use head -c only if available

This commit is contained in:
Kovid Goyal 2022-03-07 21:48:06 +05:30
parent 5e457da30b
commit 84303cbf2e
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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"; }