From 57be774f88490615423ffcd03a8075ddb61f3b6f Mon Sep 17 00:00:00 2001 From: Alissa Huskey Date: Mon, 6 Jul 2020 02:18:53 -0600 Subject: [PATCH] Fix gnu stat flag - fix gnu stat formatting option from %z to %Z - use read with a one second timeout instead of sleep, then quit if user responds with "q" (for testing, mostly) - call pager_exec on entr and bat line instead of main so that --clear works --- src/batwatch.sh | 17 ++++++++++++----- .../batwatch/test_displayed.stdout.snapshot | 4 ++++ test/suite/batwatch.sh | 11 +++++------ 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 test/snapshot/batwatch/test_displayed.stdout.snapshot diff --git a/src/batwatch.sh b/src/batwatch.sh index 183c135..a04a9b6 100755 --- a/src/batwatch.sh +++ b/src/batwatch.sh @@ -52,7 +52,7 @@ watcher_entr_watch() { ENTR_ARGS+=('-c') fi - entr "${ENTR_ARGS[@]}" \ + pager_exec entr "${ENTR_ARGS[@]}" \ "$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \ --terminal-width="$OPT_TERMINAL_WIDTH" \ --paging=never \ @@ -77,7 +77,7 @@ determine_stat_variant() { local varient name cmd ts - for varient in "gnu -c %z" "bsd -f %m"; do + for varient in "gnu -c %Z" "bsd -f %m"; do name="${varient%% *}" cmd="stat ${varient#* }" # keep the results of the stash command @@ -123,10 +123,11 @@ watcher_poll_watch() { clear fi - "$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \ + pager_exec "$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \ --terminal-width="$OPT_TERMINAL_WIDTH" \ --paging=never \ "${files[@]}" + fi local i=0 @@ -141,7 +142,13 @@ watcher_poll_watch() { ((i++)) done - sleep 1 + read -r -t 1 input + + if [[ "$input" =~ [q|Q] ]]; then + exit + fi + + input= done "${POLL_STAT_COMMAND[@]}" "$@" @@ -256,5 +263,5 @@ main() { return $? } -pager_exec main +main exit $? diff --git a/test/snapshot/batwatch/test_displayed.stdout.snapshot b/test/snapshot/batwatch/test_displayed.stdout.snapshot new file mode 100644 index 0000000..04ea15f --- /dev/null +++ b/test/snapshot/batwatch/test_displayed.stdout.snapshot @@ -0,0 +1,4 @@ +echo Hello, test world! +if true; then + ! true +fi diff --git a/test/suite/batwatch.sh b/test/suite/batwatch.sh index 4a272f4..717a877 100644 --- a/test/suite/batwatch.sh +++ b/test/suite/batwatch.sh @@ -22,11 +22,10 @@ test:help() { batwatch --help | grep -q 'Usage' } -test:watcher() { - description "Test 'batwatch '" - fail "No longer fails silently due to incorrect flag to stat." +test:displayed() { + description "Test 'batwatch ': should be displayed'" + snapshot stdout - # Refactored to get here, but when it passes it will loop forever. - - assert batwatch $0 + batwatch --no-clear --watcher poll file.sh <<< "q" + batwatch --watcher poll file.sh <<< "q" | grep -q "Hello" }