From 2a4aa3db06e08c572ee9b8b930032be1110c4645 Mon Sep 17 00:00:00 2001 From: Ethan P Date: Mon, 27 Apr 2020 04:01:12 -0700 Subject: [PATCH] batgrep/batwatch: Update to use terminal width opt hook instead of tput cols --- src/batgrep.sh | 7 ++++--- src/batwatch.sh | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/batgrep.sh b/src/batgrep.sh index 6f37f3f..a033348 100755 --- a/src/batgrep.sh +++ b/src/batgrep.sh @@ -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. diff --git a/src/batwatch.sh b/src/batwatch.sh index cd8d24f..50bfc7b 100755 --- a/src/batwatch.sh +++ b/src/batwatch.sh @@ -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") ;;