How to set up shell alias so I can change directories

I use bower and grunt in my workflow, and I wanted to install bower at the same time as grunt and pull down all my bower dependencies. So I created a package.json file that has a script attached on postinstall, which I also pass my github project repo, and dropped my post_install.sh into /root/bin.

{ // snippet of package.json
    ...
    "scripts": {
       "postinstall": "bin\\post_install.sh https://github.com/blah/blah.git
    },
    ...
}

so running npm install would run post_install.sh, which runs

#!/bin/bash
node_modules/.bin/bower install
grunt setup
git init
git add .
git commit -m "Initial commit of project artifacts"
git remote add origin $1
git push -u origin master

This only works if I set git bash to open in my project directory. So I've been trying to figure out how to switch directories from where git bash opens at /htdocs to /htdocs/myproject using an alias. I read up on how to set this I thought, but I can't figure out how to invoke this file... incidentally also tried putting it in another .sh file to see if that worked.

#!.bashrc
alias projDir='cd /onloadsolutions'

What am I doing wrong that the alias above in /bin/.bashrc won't execute in my post_install.sh when dropped above "grunt setup"?

Dropping this into post_install.sh

echo "script running has basename `basename $0`, dirname `dirname $0`"
echo "present working directory is `pwd`"

gives a basename of D:/htdocs/onloadsolutions/bin/post_install.sh, but my present working directory is /d/htdocs, which when the bower and git commands run they do it in the wrong directory.

Not 100% sure what you mean but I am guessing when you open bash you want to

  1. be able to type a command to take you to your project
  2. then type npm install and have it pull down all your dependencies

Try editing your .bashrc file (this should be in your home directory, not in the /bin folder) to access this you can use something like

nano ~/.bashrc

(~/ is a shortcut to your home directory)

and look in it for any existing alias commands or add yours down the bottom.

then after opening another bash session (.bashrc only runs when you first start terminal) you should be able to see your current aliases by typing "alias"

you can launch the alias you mentioned above by typeing "projDir" into the console. It would be much better to add the full path in your alias i.e.

alias projDir='cd /var/www/onloadsolutions'

then you can call it from anywhere. Otherwise you might end up in a different folder than you expect.

UPDATE See comments below.

Put cd $2 in the second to top line of the post_install.sh file and add a second parameter to the package.json file that calls it.