0

This is a "fun" question with some level of serious application. I like chav lingo and I was thinking it would be pretty cool to run npm innit instead of npm init. I know broadly npm allows aliases through package.json (eg when you run scripts) eg npm run innit would be trivial. however that's not really what I'm going for. I want to alias npm innit to npm init. just wondering if theres a way. i've looked through npm help as well as .bash_profile alias instructions on macosx but they dont really allow for space-separated aliases...

please let me know if you have any ideas. would help me learn aliasing more generally too.

thank you.

swyx
  • 2,378
  • 5
  • 24
  • 39
  • I would define a function for this. According to the bash manual: *For almost every purpose, aliases are superseded by shell functions.* :) – pynexj Aug 01 '17 at 02:32

3 Answers3

5

From the Bash Reference Manual:

If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion.

So you can do this:

alias npm='npm ' # The trailing space is important
alias innit='init'
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
0

you can use the following alias for npm cmd

alias nib="npm i && npm run bootstrap"
alias nb="npm run bootstrap"
alias ncib="npm run clean && npm i && npm run bootstrap"
saurabhshcs
  • 797
  • 5
  • 6
0

Actually, this alias is already defined in NPM by default, and has been at least since this answer was posted in 2019, and is now documented in the v8.x docs.

npm init <package-spec> (same as `npx <package-spec>)
npm init <@scope> (same as `npx <@scope>/create`)

aliases: create,innit

I believe this is just in case people misspell init, though it's possible that it was added as a humorous thought by the NPM devs.

Jacob
  • 1,577
  • 8
  • 24