-
Copy the aliases to
.profile
/.bashrc
/ wherever you like -
Use
npmrun
instead ofnpm run
, enjoy
$ npmrun[TAB]
run-debug run-prod tdd test-bar test-foo
$ npmrun te[TAB]
test-bar test-foo
$ npmrun test-bar
On big projects, there are usually many technologies and tools used - for running builds, partial builds, tests, partial tests, etc. Often you have helper scripts to run those tools.
The common problems of all those little tools are the following:
- they might be spread over the repo in the subfolders (to not pollute the root folder with lots of random scripts)
- they might be run in a different way (sometimes as a shell scripts written in bash / nodejs / python etc., sometimes through third party runner like
grunt
/gulp
) - your
Gruntfile
might have many subtasks embedded, you commonly use many of them, not only the default one - in each of your repos, those helper scripts / grunt task are named differently, located in different place etc.
- you don't get autocompletion in console for grunt tasks names, parameter names etc.
Hence, it's helpful to list all your scripts in one place. A good place for this is package.json
:
{
"name": "foo",
"scripts": {
"run-debug": "bash scripts/run-debug.sh",
"run-prod": "bash scripts/run-prod.sh",
"test-foo": "grunt test:foo",
"test-bar": "grunt test:bar",
"tdd": "grunt tdd"
}
}
and now you can npm run [scriptname]
(npm run
is a shortcut for npm run-script
).
But the problem of autocompletion is still unsolved.
There comes npmrun
which is just an alias to npm run
, but we additionally establish bash autocompletion for it by reading package.json
contents and running bash machinery (complete
bash builtin) that will enable the completion.
Nice gist! Thanks for it, but if I have a script named
build:css
, and I type the following in my terminal,Then it autocompletes to,
Maybe it doesn't handle script names with colons in them quite properly? Any ideas where to poke around?