Skip to content

Instantly share code, notes, and snippets.

@arialdomartini
Created October 20, 2026 07:04
Show Gist options
  • Select an option

  • Save arialdomartini/655d59e7763d1e54edfad1b0e8153f6f to your computer and use it in GitHub Desktop.

Select an option

Save arialdomartini/655d59e7763d1e54edfad1b0e8153f6f to your computer and use it in GitHub Desktop.
jj-watch
#!/usr/bin/env bash
# Refresh jj log whenever the latest Jujutsu operation changes.
#
# JJ_LOG_WATCH_INTERVAL to change the polling interval (default: 0.5 seconds).
set -u
interval="${JJ_LOG_WATCH_INTERVAL:-0.5}"
latest_operation() {
# Keep the watcher from snapshotting the working copy and
# accidentally creating an operation of its own.
jj --at-op=@ --ignore-working-copy operation log --limit 1 --no-graph --template 'id'
}
render_log() {
# Clear the terminal and position the cursor at its top-left corner.
clear && jj st && echo && jj log
}
previous_operation="$(latest_operation)" || {
echo "Unable to read the latest Jujutsu operation." >&2
exit 1
}
render_log
while sleep "$interval"; do
current_operation="$(latest_operation)" || continue
if [[ "$current_operation" != "$previous_operation" ]]; then
previous_operation="$current_operation"
render_log
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment