feat: add --watch flag for live file reload#3645
Open
konaito wants to merge 4 commits intosharkdp:masterfrom
Open
feat: add --watch flag for live file reload#3645konaito wants to merge 4 commits intosharkdp:masterfrom
konaito wants to merge 4 commits intosharkdp:masterfrom
Conversation
Add a `--watch` / `-w` option that monitors files for changes and automatically clears the screen and re-displays them with syntax highlighting when modified externally (e.g. in VS Code, nano, vim). This uses the `notify` crate to watch the parent directory of each file, which correctly handles editors that perform atomic saves (write to temp file + rename). Includes 100ms debouncing to coalesce rapid events. Paging is automatically disabled in watch mode. Press Ctrl+C to stop. Closes sharkdp#852 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Replace redundant closures with Input::ordinary_file - Use contains() instead of iter().any() for path matching - Update short-help.txt and long-help.txt with --watch flag Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--watch/-woption that monitors files for changes using thenotifycrateUsage
Motivation
This addresses a common workflow where developers view a file with bat in one terminal while editing it in another (VS Code, nano, vim, etc). Currently, users must manually re-run bat to see changes. With
--watch, the display stays up-to-date automatically — similar totail -fbut for the entire file with syntax highlighting.Closes #852
Test plan
cargo buildsucceedscargo test --lib— all 116 tests passbat --watch file.jsondisplays file, updates on external edit, stops on Ctrl+Cbat --watchwithout file argument shows helpful errorbat --helpshows--watchflag with description🤖 Generated with Claude Code