Re:Ask HN: What's the best obscure but useful CLI tool?
by john-tells-all on Wednesday April 05, 2023 @11:58AM
(#35456280)
entr -- when a file changes, run a command
I use this on literally 100% of my projects. Normally it's "when my source changes, run tests" or sometimes "when files change, do 'terraform plan' to see what would change".
Using this one command shortens developer feedback loops from a minute to microseconds! And you don't have to think about it! It's magic.
Re:Ask HN: What's the best obscure but useful CLI tool?
by anthonyhn on Wednesday April 05, 2023 @03:50PM
(#35459517)
GNU Parallel is pretty useful. You can use it to run command line programs in parallel. For example, if you wanted to gzip compress all individual files in a directory and limit the number of jobs equal to the number of CPU cores on your machine:
ls | parallel --dry-run --jobs `nproc` 'gzip {}'
(Note you have to remove the --dry-run switch to actually run this, --dry-run only prints out the commands parallel will run, not actually execute them)
I use this on literally 100% of my projects. Normally it's "when my source changes, run tests" or sometimes "when files change, do 'terraform plan' to see what would change".
Using this one command shortens developer feedback loops from a minute to microseconds! And you don't have to think about it! It's magic.
`ls -1 *.py | entr pytest`
`git ls-files | entr terraform plan`
For more, see our friend and national treasure Julia Evans: https://jvns.ca/blog/2020/06/28/entr/
I love it!
ls | parallel --dry-run --jobs `nproc` 'gzip {}'
(Note you have to remove the --dry-run switch to actually run this, --dry-run only prints out the commands parallel will run, not actually execute them)