batgrep/batwatch: Update to use terminal width opt hook instead of tput cols

This commit is contained in:
Ethan P 2020-04-27 04:01:12 -07:00 committed by Ethan P
parent ab0f1b96d6
commit b2bc772ad1
2 changed files with 8 additions and 7 deletions

View File

@ -12,6 +12,7 @@ source "${LIB}/print.sh"
source "${LIB}/pager.sh"
source "${LIB}/opt.sh"
source "${LIB}/opt_hooks.sh"
source "${LIB}/opt_hook_width.sh"
source "${LIB}/version.sh"
# -----------------------------------------------------------------------------
# Init:
@ -19,6 +20,7 @@ source "${LIB}/version.sh"
hook_color
hook_pager
hook_version
hook_width
# -----------------------------------------------------------------------------
# Options:
# -----------------------------------------------------------------------------
@ -132,8 +134,7 @@ if [[ -z "$PATTERN" ]]; then
fi
# Generate separator.
COLS="$(tput cols)"
SEP="$(printc "%{DIM}%${COLS}s%{CLEAR}" | sed "s/ /─/g")"
SEP="$(printc "%{DIM}%${OPT_TERMINAL_WIDTH}s%{CLEAR}" | sed "s/ /─/g")"
# Append ripgrep and bat arguments.
if [[ -n "$OPT_CASE_SENSITIVITY" ]]; then
@ -205,7 +206,7 @@ main() {
"${LAST_LH[@]}" \
--style="${BAT_STYLE}${OPT_SNIP}" \
--paging=never \
--terminal-width="$COLS" \
--terminal-width="$OPT_TERMINAL_WIDTH" \
"$LAST_FILE"
# Print the separator.

View File

@ -10,6 +10,7 @@ LIB="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd "$(dirname "$(readlink "${BASH_
source "${LIB}/constants.sh"
source "${LIB}/opt.sh"
source "${LIB}/opt_hooks.sh"
source "${LIB}/opt_hook_width.sh"
source "${LIB}/print.sh"
source "${LIB}/pager.sh"
# -----------------------------------------------------------------------------
@ -18,6 +19,7 @@ source "${LIB}/pager.sh"
hook_color
hook_pager
hook_version
hook_width
# -----------------------------------------------------------------------------
# Watchers:
# -----------------------------------------------------------------------------
@ -35,7 +37,7 @@ watcher_entr_watch() {
entr "${ENTR_ARGS[@]}" \
"$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \
--terminal-width="$TERM_WIDTH" \
--terminal-width="$OPT_TERMINAL_WIDTH" \
--paging=never \
"$@" \
< <(printf "%s\n" "$@")
@ -98,7 +100,7 @@ watcher_poll_watch() {
fi
"$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \
--terminal-width="$TERM_WIDTH" \
--terminal-width="$OPT_TERMINAL_WIDTH" \
--paging=never \
"${files[@]}"
fi
@ -151,7 +153,6 @@ FILES=()
FILES_HAS_DIRECTORY=false
OPT_CLEAR=true
OPT_WATCHER=""
TERM_WIDTH="$(tput cols)"
# Set options based on tty.
if [[ -t 1 ]]; then
@ -166,7 +167,6 @@ while shiftopt; do
--watcher) shiftval; OPT_WATCHER="$OPT_VAL" ;;
--clear) OPT_CLEAR=true ;;
--no-clear) OPT_CLEAR=false ;;
--terminal-width) shiftval; TERM_WIDTH="$OPT_VAL" ;;
# bat/Pager options
-*) BAT_ARGS+=("$OPT=$OPT_VAL") ;;