Skip to content

Instantly share code, notes, and snippets.

@Exponential-Workload
Last active April 6, 2024 21:52
Show Gist options
  • Save Exponential-Workload/74b56ffc23f3c6e17970c1458006db14 to your computer and use it in GitHub Desktop.
Save Exponential-Workload/74b56ffc23f3c6e17970c1458006db14 to your computer and use it in GitHub Desktop.
watch.sh: A simple script for getting up-to-date command output faster, without stdout flickering
#!/usr/bin/env zsh
set -eax
# Do not run this with untrusted argv!
# Usage Example: ./watch.sh curl -fsSL http://66117b5a7483e49ba3af.functions.localhost/log
A="$RANDOM"
B="$RANDOM"
while true; do
A="$($@)";
if [[ "$B" != "$A" ]]; then
echo -e "\x1b[H\x1b[2J\x1b[3J$A";
B="$A"
fi;
sleep "${INTERVAL:-0.2s}";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment