zsh auto_cd + gulp global command conflict fix

04 Mar 2015 . tech . Comments #node.js #gulp.js #zsh #oh-my-zsh #auto_cd #shell #terminal

I use ZSH for my shell, and specifically oh-my-zsh for templating and configuration. ZSH adds in a lot of sweet functionality, like a more advanced autocomplete system, for example.

When setting up a new project with gulp, however, I’ve run into an interesting issue. I break out my gulp tasks into a separate subfolder, named gulp/. Should be fine, right? So long as there is a gulpfile.js in the root of the project, you can require in whatever you want.

Here’s the issue: zsh is so smart, it checks your input to see if it’s a subdirectory in your pwd, and if it is, it auto cd ‘s into the folder. So instead of using my global gulp command like it normally does, it just jumps me into that task folder. Super annoying.

The reason this is occurring is because the AUTO_CD feature is enabled in my shell. I prefer to not have this feature enabled at all, so I opted to disable it. If I were to be using vanilla zsh, I would just comment out that line in my .zshrc or .zsh_profile file. Since I’m using oh-my-zsh, All I needed to do was comment out line 23 in ~/.oh-my-zsh/lib/theme-and-appearance.zsh. All taken care of.

If you dislike the idea of disabling that feature, however, try adding the gulp command to the package.json file in your project, like this:

    	"gulp": "./node_modules/gulp/bin/gulp.js"

Make sure you have gulp installed and saved in your dev dependencies, and run npm run gulp, and it should run like a charm. This also solves the issue of someone wanting to run dev on their system without globally installing gulp, which some developers prefer.

I went through this on a recent iojs/website PR, if you want to see it all in action.