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
parent 6f17ee67ba
commit 2a4aa3db06
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
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}/pager.sh"
source "${LIB}/opt.sh" source "${LIB}/opt.sh"
source "${LIB}/opt_hooks.sh" source "${LIB}/opt_hooks.sh"
source "${LIB}/opt_hook_width.sh"
source "${LIB}/version.sh" source "${LIB}/version.sh"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Init: # Init:
@ -19,6 +20,7 @@ source "${LIB}/version.sh"
hook_color hook_color
hook_pager hook_pager
hook_version hook_version
hook_width
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Options: # Options:
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -132,8 +134,7 @@ if [[ -z "$PATTERN" ]]; then
fi fi
# Generate separator. # Generate separator.
COLS="$(tput cols)" SEP="$(printc "%{DIM}%${OPT_TERMINAL_WIDTH}s%{CLEAR}" | sed "s/ /─/g")"
SEP="$(printc "%{DIM}%${COLS}s%{CLEAR}" | sed "s/ /─/g")"
# Append ripgrep and bat arguments. # Append ripgrep and bat arguments.
if [[ -n "$OPT_CASE_SENSITIVITY" ]]; then if [[ -n "$OPT_CASE_SENSITIVITY" ]]; then
@ -205,7 +206,7 @@ main() {
"${LAST_LH[@]}" \ "${LAST_LH[@]}" \
--style="${BAT_STYLE}${OPT_SNIP}" \ --style="${BAT_STYLE}${OPT_SNIP}" \
--paging=never \ --paging=never \
--terminal-width="$COLS" \ --terminal-width="$OPT_TERMINAL_WIDTH" \
"$LAST_FILE" "$LAST_FILE"
# Print the separator. # 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}/constants.sh"
source "${LIB}/opt.sh" source "${LIB}/opt.sh"
source "${LIB}/opt_hooks.sh" source "${LIB}/opt_hooks.sh"
source "${LIB}/opt_hook_width.sh"
source "${LIB}/print.sh" source "${LIB}/print.sh"
source "${LIB}/pager.sh" source "${LIB}/pager.sh"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -18,6 +19,7 @@ source "${LIB}/pager.sh"
hook_color hook_color
hook_pager hook_pager
hook_version hook_version
hook_width
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Watchers: # Watchers:
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -35,7 +37,7 @@ watcher_entr_watch() {
entr "${ENTR_ARGS[@]}" \ entr "${ENTR_ARGS[@]}" \
"$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \ "$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \
--terminal-width="$TERM_WIDTH" \ --terminal-width="$OPT_TERMINAL_WIDTH" \
--paging=never \ --paging=never \
"$@" \ "$@" \
< <(printf "%s\n" "$@") < <(printf "%s\n" "$@")
@ -98,7 +100,7 @@ watcher_poll_watch() {
fi fi
"$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \ "$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \
--terminal-width="$TERM_WIDTH" \ --terminal-width="$OPT_TERMINAL_WIDTH" \
--paging=never \ --paging=never \
"${files[@]}" "${files[@]}"
fi fi
@ -151,7 +153,6 @@ FILES=()
FILES_HAS_DIRECTORY=false FILES_HAS_DIRECTORY=false
OPT_CLEAR=true OPT_CLEAR=true
OPT_WATCHER="" OPT_WATCHER=""
TERM_WIDTH="$(tput cols)"
# Set options based on tty. # Set options based on tty.
if [[ -t 1 ]]; then if [[ -t 1 ]]; then
@ -166,7 +167,6 @@ while shiftopt; do
--watcher) shiftval; OPT_WATCHER="$OPT_VAL" ;; --watcher) shiftval; OPT_WATCHER="$OPT_VAL" ;;
--clear) OPT_CLEAR=true ;; --clear) OPT_CLEAR=true ;;
--no-clear) OPT_CLEAR=false ;; --no-clear) OPT_CLEAR=false ;;
--terminal-width) shiftval; TERM_WIDTH="$OPT_VAL" ;;
# bat/Pager options # bat/Pager options
-*) BAT_ARGS+=("$OPT=$OPT_VAL") ;; -*) BAT_ARGS+=("$OPT=$OPT_VAL") ;;