saw

Saw Ain't Watch

Execute a command repeatedly and display output

View on GitHub Get Started

Installation

🍺 Homebrew (Recommended for macOS)

# Tap the repository
brew tap jasonlotito/saw

# Install saw
brew install saw

Or install in one command: brew install jasonlotito/saw/saw

📥 Manual Install

# Download the script
curl -O https://raw.githubusercontent.com/jasonlotito/saw/main/saw
chmod +x saw

# Move to a directory in your PATH
sudo mv saw /usr/local/bin/

📦 Requirements

  • bash - Required (usually pre-installed)
  • fswatch - Optional, for file watching feature (brew install fswatch)

Why saw?

⏱️ Smart Timing

Unlike watch, saw waits for your command to finish before starting the interval timer.

  • No overlapping executions
  • Perfect for long-running commands
  • Predictable behavior

🎯 Execution Limits

Control exactly how many times or how long your command runs.

  • Max runs: -r 10
  • Max time: -m 5m
  • Environment variables supported

📡 Signal Triggering

Trigger immediate runs on demand without waiting for the interval.

  • Listen for SIGUSR1 signals
  • Perfect for event-driven workflows
  • Integrate with file watchers

👀 File Watching

Automatically run commands when files change using fswatch integration.

  • Zero manual setup
  • Recursive directory monitoring
  • Automatic cleanup

Examples

Basic Usage

# Watch file line count every 2 seconds
saw wc -l contributions.txt

# Custom interval of 5 seconds
saw -n 5 ls -la

# Using environment variable
INT=10 saw git status

Execution Limits

# Run exactly 10 times
saw -r 10 echo "hello"

# Run for 30 seconds
saw -m 30s date

# Run for 5 minutes with 10-second intervals
saw -m 5m -n 10 uptime

# Combine limits
saw -r 100 -m 5m ./my-script.sh

Signal Triggering

# Start saw in signal mode
saw -s npm test &

# Trigger immediate run from another terminal
kill -USR1 $(pgrep -f 'saw.*npm test')

# Combine with file watcher
fswatch -o ./src | xargs -n1 -I{} kill -USR1 $SAW_PID

File Watching

# Watch src directory and run tests on changes
saw -w ./src npm test

# Watch current directory and rebuild
saw --watch . npm run build

# Watch with custom interval between checks
saw -w ./app -n 10 'make build'

saw vs watch

Feature saw watch
Waits for command to finish
Execution limits (max runs)
Time limits (max time)
Signal triggering (SIGUSR1)
File watching integration
Fixed interval execution
Screen clearing
Highlight differences

Key difference: watch runs on a fixed interval regardless of command duration. saw waits for the command to complete, then waits the interval before running again.