2020-05-03 01:58:17 +02:00
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
# bat-extras | Copyright (C) 2020 eth-p | MIT License
|
|
|
|
#
|
|
|
|
# Repository: https://github.com/eth-p/bat-extras
|
|
|
|
# Issues: https://github.com/eth-p/bat-extras/issues
|
|
|
|
# -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Gets the width of the terminal.
|
|
|
|
# This will return 80 unless stdin is attached to the terminal.
|
|
|
|
#
|
|
|
|
# Returns:
|
|
|
|
# The terminal width, or 80 if there's no TTY.
|
|
|
|
#
|
|
|
|
term_width() {
|
2020-05-03 02:11:30 +02:00
|
|
|
# shellcheck disable=SC2155
|
|
|
|
local width="$({ stty size 2>/dev/null || echo "22 80"; } | cut -d ' ' -f2)"
|
|
|
|
if [[ "$width" -ne 0 ]]; then
|
|
|
|
echo "$width"
|
|
|
|
else
|
2020-05-03 01:58:17 +02:00
|
|
|
echo "80"
|
|
|
|
fi
|
2020-05-03 02:03:53 +02:00
|
|
|
return 0
|
2020-05-03 01:58:17 +02:00
|
|
|
}
|