Run one command interactively in the foreground, while other commands run in the background.
Use cases:
- Running linting and typechecking while writing commit messages, instead of after or before like with git hooks
- Probably others, but commits is the reason I wrote this for
yarn add run-behind --dev
# or
npm install run-behind --save-dev
yarn run-behind <foreground-command> <background-command-1> <background-command-2> ... <background-command-n>
// ...
scripts: {
"lint": "eslint src --ext .js,.ts --cache",
"typecheck": "tsc --noEmit --incremental",
"commit": "run-behind git-cz 'yarn lint' 'yarn typecheck'"
}
// ...
Install globally:
npm install -g run-behind
Add an alias to ~/.zshrc
or equivalent for easy usage
alias gc=run-behind git-cz 'yarn lint --quiet' 'yarn typecheck --pretty'
If you want to get back to your terminal without waiting for the tasks to end, just hit ctrl-c.
Things will be commmited even if the background command fail. It's not a bug, it's a feature. You can use git commit --amend
if it turns out something failed.
Setting up caching for the commands will make the experience a lot better:
eslint
: just add--cache
to the commandtsc
: use--incremental
jest
: usually caching is set up by default, you can add--onlyChanged
to only run relevant tests