Skip to content
Browse files

Finished up the Tab Completion section

  • Loading branch information...
1 parent fb9e50c commit 76eeb1358b5c3be94385c7d04ded5f3facad0ba2 @croach committed Jul 3, 2012
Showing with 6 additions and 2 deletions.
  1. +6 −2 02.md
View
8 02.md
@@ -111,13 +111,17 @@ The main reason that I'm running through all the different ways to view the docs
### Tab completion
-In the meantime, we still have a few other features to cover before we finish up, so let's move on to the next one, tab completion. If you type `npm completion` into the command line, you'll get back a print out of the shell script that sets everything up. Type `npm help completion` to get some instructions on how to install it. The second line in the Description section tells us what to do. Specifically, we just need to copy the Synopsis line into our startup file for whatever shell we run. Let's go ahead and set that up now by just copying this line and exiting help, and then opening up our `.bashrc` file and pasting this right underneath the lines we added earlier for nvm. I'm going to go ahead and add another if clause around this command as well just to make sure that I have npm installed before it tries to run it. Let me add that now:
+But before you go off and get lost in the docs, I still want to cover a few more features that you might find useful. So, let's go ahead and move onto the next one---tab completion.
+
+If you type `npm completion` into the command line, you'll get back a print out of the shell function that will set everything up for us, but just how do we use it? Well, of course, we're going to go to the docs to find out, right? So, go ahead and type `npm help completion` to get some instructions on how to install it. The second line in the Description section tells us what to do. Specifically, we just need to copy the line in the Synopsis section above into our startup file for whatever shell we run.
+
+Let's go ahead and set that up now by just copying this line and exiting the help, and then opening up our `.bashrc` file and pasting this right underneath the lines we added earlier for nvm. I'm going to go ahead and add another `if` clause around this command as well just to make sure that I have npm installed before it tries to run it. Let me add that now:
if npm -v >/dev/null 2>&1; then
. <(npm completion)
fi
-Now if you save that and open a new shell, hopefully everything executes properly and you don't see any error statements. If that's true, then try out the tab completion by typing `npm comp-TAB` and the rest should be filled in for you. Now this worked just fine for me in zsh, but for some reason, I had troubles with this setup in bash. So, if you're running bash and when you open a new shell you see several errors from npm starting with something like `Error: write EPIPE`, a workaround I've found is to simply replace the Synopsis line in the `.bashrc` file with the full text from the `npm completion` command. So, I'll go ahead and pop back out to my command line and run `npm completion` and copy that and go back to my `.bashrc` file and paste it within the `if` statement I added earlier. Now, if you open another shell, everything should be working correctly.
+Now if you save that and open a new shell, hopefully everything executes properly and you don't see any error statements. If that's true, then try out the tab completion by typing `npm comp-TAB` and the rest should be filled in for you. Now this worked just fine for me in zsh, but for some reason, I had troubles with this setup in bash. So, if you're running bash, and, when you open a new shell you see several errors from npm starting with something like `Error: write EPIPE`, a workaround I've found is to simply replace the Synopsis line in the `.bashrc` file with the full text from the `npm completion` command. So, I'll go ahead and pop back out to my command line and run `npm completion` and copy that and go back to my `.bashrc` file and paste it within the `if` statement I added earlier. Now, if you open another shell, everything should be working correctly.
### Search and info

0 comments on commit 76eeb13

Please sign in to comment.
Something went wrong with that request. Please try again.