Register command completion scripts for bash
shell.
The setup.sh
will add completion scripts to the file ~/.bashrc
:
-
File
npm.sh
:-
Commands:
npm {install | i | add | remove | rm | uninstall | un}
.yarn {install | i | add | remove | rm | uninstall | un}
.pnpm {install | i | add | remove | rm | uninstall | un}
.
Note:
install
is not a valid command foryarn
andpnpm
oradd
is not a valid command fornpm
, but the completion script still works. Because I'm just lazy to write a script to check the command 😅. -
Description:
-
Search in current directory for all
package.json
files (not innode_modules
directory), then register completions fordependencies
anddevDependencies
packages specified in the filepackage.json
, when command isinstall
,add
,remove
. This completion is registered for the commandnpm
,yarn
andpnpm
. -
This script should be included in
~/.bashrc
file, so it will be executed when a new shell is started. Moreover, when the script is executed inHOME
directory, it can find allpackage.json
files in your system, and give you better completion.
-
-
Commands:
npm
yarn
pnpm
-
Description:
- This is default case, so it will behave the same as the above case, but it
will register completions for
scripts
inpackage.json
file instead of thedependencies
anddevDependencies
.
- This is default case, so it will behave the same as the above case, but it
will register completions for
-
Usage:
source ./npm.sh
-
Run setup.sh
to setup completions:
./setup.sh