Casa de Lewis

19 April 2011

Command Alias in Command Prompt Using Windows 7

I recently organized my projects and in doing so I created some very long paths to type into the command prompt when using git and SCSS. I came across just what I was looking for to alleviate the verbose typing and thought I would share it here since I found it to be quite an obscure command name.

doskey

Instead of having to type, cd "C:/Users/Mark/Documents/Projects/Symphony/Foo" now I can simply type foo into the command prompt.

To achieve the result above, I set up an alias by typing, doskey foo=cd "C:/Users/Mark/Documents/Projects/Symphony/Foo" into the command prompt.

doskey is a huge timesaver, so start using it now!

There’s a catch

Once you close the command prompt all doskey shortcut are lost. So, what to do? Well, doskey allows you to create a file containing all of your shortcuts. You can then load this file at the beginning of your session by issuing the following command, doskey /macrofile=FILE_LOCATION.

But, that wasn’t good enough for me. I didn’t want to have to enter that each time I started the command prompt. So, again, what to do? The solution is to edit your registry to include a value for Autorun. Open the registry editor and navigate to HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Command Processor/. Since I did not already have Autorun, I right clicked in the right-hand side of the screen, selected new, and then String Value. Name it Autorun and then double-click it. Put the command doskey /macrofile=FILE_LOCATION for its value.

Now, every time you start the command prompt, the file containing your shortcuts will be automatically loaded and available to use immediately.