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

View File

@@ -94,12 +94,18 @@ else
return $? return $?
} }
read_n_bytes_from_tty() { # using dd with bs=1 is very slow, so use head. On non GNU coreutils head
# 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
# 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.
# 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
command head -c "$1" < /dev/tty 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 fi
debug() { dcs_to_kitty "print" "debug: $1"; } debug() { dcs_to_kitty "print" "debug: $1"; }