mirror of
https://github.com/notwa/rc
synced 2024-06-01 15:33:07 -07:00
detect size with stty size
instead of tput
This commit is contained in:
parent
38cd399bcf
commit
f0fedca16f
20
sh/glug
20
sh/glug
|
@ -19,11 +19,21 @@ glug() ( # note the subshell syntax. this allows us to abuse globals like crazy.
|
||||||
done
|
done
|
||||||
cd "$_here"
|
cd "$_here"
|
||||||
|
|
||||||
if [ -z "$ZSH_VERSION" ]; then
|
detect_size() {
|
||||||
# TODO: is `stty size` more portable?
|
# globals: $COLUMNS, $LINES
|
||||||
COLUMNS="${COLUMNS:-$(tput cols)}"
|
_size="$(stty size)"
|
||||||
LINES="${LINES:-$(tput lines)}"
|
COLUMNS="${_size#* }"
|
||||||
fi
|
LINES="${_size%% *}"
|
||||||
|
if [ "$COLUMNS" -gt 0 ] 2>/dev/null && [ "$LINES" -gt 0 ] 2>/dev/null; then
|
||||||
|
: # pass
|
||||||
|
else
|
||||||
|
printf '%s: failed to determine terminal size\n' glug >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
unset _size
|
||||||
|
}
|
||||||
|
|
||||||
|
[ -n "$ZSH_VERSION" ] || detect_size
|
||||||
|
|
||||||
if [ -n "$ZSH_VERSION" ] || [ -n "$BASH_VERSION" ]; then
|
if [ -n "$ZSH_VERSION" ] || [ -n "$BASH_VERSION" ]; then
|
||||||
esc=$'\e'
|
esc=$'\e'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user