mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-07-11 02:03:22 +00:00
Use head -c only if available
This commit is contained in:
parent
5e457da30b
commit
84303cbf2e
1 changed files with 12 additions and 6 deletions
|
|
@ -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"; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue