lib/watch.sh

341 B · 20 lines · bash

1#!/usr/bin/env bash
2
3brt_watch() {
4 local cmd="${*:-}"
5 if [[ -z "$cmd" ]]; then
6 brt_error "Usage: brt -watch <command>"
7 exit 1
8 fi
9
10 brt_info "Watching — re-running: ${cmd}"
11 brt_info "Press Ctrl+C to stop"
12
13 while true; do
14 clear 2>/dev/null || true
15 echo "── $(date) ──"
16 eval "$cmd"
17 sleep 2
18 done
19}
20