bat-extras/lib/opt_hook_width.sh
2020-04-27 04:00:44 -07:00

28 lines
774 B
Bash

#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# bat-extras | Copyright (C) 2019 eth-p | MIT License
#
# Repository: https://github.com/eth-p/bat-extras
# Issues: https://github.com/eth-p/bat-extras/issues
# -----------------------------------------------------------------------------
# Option parser hook: --terminal-width support.
# This will accept --terminal-width=number.
#
# The variable OPT_TERMINAL_WIDTH will be set.
hook_width() {
SHIFTOPT_HOOKS+=("__shiftopt_hook__width")
__shiftopt_hook__width() {
case "$OPT" in
--terminal-width) shiftval; OPT_TERMINAL_WIDTH="$OPT_VAL" ;;
*) return 1 ;;
esac
return 0
}
# Default terminal width.
OPT_TERMINAL_WIDTH="$(stty size | cut -d' ' -f 2)"
}