Home

Print A File In The Terminal Every Time It Changes

This uses [TODO: Code shorthand span ]. I've since converted over to using [TODO: Code shorthand span ] which I find more robust.

Use this to output a file every time it changes

fswatch -0 ~/path/to/file.txt | xargs -0 -n1 cat

Some apps will update when files change, but lots of times they'll only do that if they are in focus. This command prints the file out to the terminal every time it changes.

- You can pass regular expressions in instead of a single file

- You can pass in multiple paths if you want to watch multiple files or directories

- fswatch sometimes fires twice for a single update. This confused me a few times until I figured it out

- It's possible to add an [TODO: Code shorthand span ] flag to only watch for updates, but that didn't stop firing twice

- I see the firing twitch from NeoVim. Might happen in other apps too

- The [TODO: Code shorthand span ] mean when multiple files are passed they are split by the NULL character. This is done to mitigate problems with spaces in file names

  • []

    Consolidate all the posts about `fswatch`

~ fin ~