Thursday, June 18, 2009

a simple intro to alias in macosx (unix) (+ doskey in windows)

From the java developer's perspective, it is very often that you will have to deal with long project strcuctures and even longer ant task names,just to get something to execute or cd to a specific folder. I was getting a bit tired when everyday i was dealing with something like that

> ant -f /Volumes/secondary/myproject/mySubprojectEar/build-all.xml database.recreate.keepUser
several other tasks or a combination of them. I could not be bothered. So I started using the alias functionality offered in the MacOSX Terminal and in any other Unix compatible shell system.

I wanted to re-load my aliases every time I was rebooting or having a new session so in one step do the following.

1. edit your .profile in your home folder
vi /Users/username/.profile

2. add the alias you want in any command you want , the format is alias aliasname ='command' .

alias dbrecreate ='ant -f /Volumes/secondary/myproject/mysubprojectear/build-all.xml db.recreate'

alias cdtoproj='cd /Volumes/secondary/myproject'

3. Save your .profile and open a new terminal

4. type dbrecreate and your ant task should be executing or just type > cdtoproj and you will cd to the above directory!

If you dont your aliases reloaded or associated with your profile you can issue the same commands from your command line and they will be valid as long as your current terminal session is valid.

For windows users :P there is the old doskey command.(winNT, 2k,XP). I think I have read somewhere that in Win7 the new Powershell has something as well.So if you want to do the same you have to type something like

c:\> doskey reachappear = cd c:\myproject\myearproj\
you can save all your macros (this is how they are called in M$ world) by
doskey /M> macros.txt and reload them using doskey /File c:\:macros.txt

1 comment:

  1. Mac users discover bash(1) and aliases. Film at eleven.