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
This commit is contained in:
Alissa Huskey 2020-07-06 02:18:53 -06:00 committed by Ethan P
parent 4c09718a46
commit 57be774f88
3 changed files with 21 additions and 11 deletions

View File

@ -52,7 +52,7 @@ watcher_entr_watch() {
ENTR_ARGS+=('-c') ENTR_ARGS+=('-c')
fi fi
entr "${ENTR_ARGS[@]}" \ pager_exec entr "${ENTR_ARGS[@]}" \
"$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \ "$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \
--terminal-width="$OPT_TERMINAL_WIDTH" \ --terminal-width="$OPT_TERMINAL_WIDTH" \
--paging=never \ --paging=never \
@ -77,7 +77,7 @@ determine_stat_variant() {
local varient name cmd ts 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#* }" name="${varient%% *}" cmd="stat ${varient#* }"
# keep the results of the stash command # keep the results of the stash command
@ -123,10 +123,11 @@ watcher_poll_watch() {
clear clear
fi fi
"$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \ pager_exec "$EXECUTABLE_BAT" "${BAT_ARGS[@]}" \
--terminal-width="$OPT_TERMINAL_WIDTH" \ --terminal-width="$OPT_TERMINAL_WIDTH" \
--paging=never \ --paging=never \
"${files[@]}" "${files[@]}"
fi fi
local i=0 local i=0
@ -141,7 +142,13 @@ watcher_poll_watch() {
((i++)) ((i++))
done done
sleep 1 read -r -t 1 input
if [[ "$input" =~ [q|Q] ]]; then
exit
fi
input=
done done
"${POLL_STAT_COMMAND[@]}" "$@" "${POLL_STAT_COMMAND[@]}" "$@"
@ -256,5 +263,5 @@ main() {
return $? return $?
} }
pager_exec main main
exit $? exit $?

View File

@ -0,0 +1,4 @@
echo Hello, test world!
if true; then
! true
fi

View File

@ -22,11 +22,10 @@ test:help() {
batwatch --help | grep -q 'Usage' batwatch --help | grep -q 'Usage'
} }
test:watcher() { test:displayed() {
description "Test 'batwatch <file>'" description "Test 'batwatch <file>': <file> should be displayed'"
fail "No longer fails silently due to incorrect flag to stat." snapshot stdout
# Refactored to get here, but when it passes it will loop forever. batwatch --no-clear --watcher poll file.sh <<< "q"
batwatch --watcher poll file.sh <<< "q" | grep -q "Hello"
assert batwatch $0
} }