Command Line Aliases

I’ve been trying to hone my command line skills as it’s sometimes the only way to do complex operations (searching remote svn log files). One of the actions I find most repeated is finding my way into the various directories to perform these operations. My typing skills are less than stellar, so it kind sucks to type (even with tab completion):

cd /Applications/MAMP/htdocs

In looking for a better way to navigate to my repo, I created an alias. This means that instead of typing:

cd /Applications/MAMP/htdocs

I can simply type:

repo

That variable will be “expanded” into the string cd /Applications/MAMP/htdocs and executed by the shell.

Here’s how make this black magic a reality:

OSX (UNIX)
—–
Open Finder and click on your home folder.
Show the hidden files using the keystroke shift + command + . (or use a dashboard widget)
Open the hidden file named “.profile” (or create one with Textedit if it doesn’t exist)
Add the following text (I use MAMP as my server, which is located at /Applications/MAMP/):

alias repo='/Applications/MAMP/htdocs'

Save the file.
Open a new Terminal (/Applications/Utilities/Terminal.app)
Type:

repo

You should now be in the /htdocs directory (or whatever path you set for repo)

Windows
——–
Open Notepad and create a new text file.
Add the following text (I use WAMP as my server, which is located at C:\wamp):

cd C:\wamp\www

Save the file as “repo.bat” in C:\WINDOWS\system32.
Open a Command Prompt at Start->All Programs->Accessories->Command Prompt (or using the Start Menu shortcut r and CMD)
Type:

repo

You should now be in the \www directory (or whatever path you set for repo)

OSX (UNIX) reference

Windows reference