lib: Fix term_width to handle cases where stty size returns '0 0'

This commit is contained in:
Ethan P 2020-05-02 17:11:30 -07:00
parent c98e21df04
commit 63101805be
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA

View File

@ -12,12 +12,12 @@
# The terminal width, or 80 if there's no TTY.
#
term_width() {
if ! [[ -t 0 ]]; then
echo "80"
return 0
fi
# shellcheck disable=SC2155
{ stty size 2>/dev/null || echo "22 80"; } | cut -d' ' -f2
local width="$({ stty size 2>/dev/null || echo "22 80"; } | cut -d ' ' -f2)"
if [[ "$width" -ne 0 ]]; then
echo "$width"
else
echo "80"
fi
return 0
}