Getting Your Macro on with DOSKEY
I’m a big fan of the command line (much to the mirth of some of my co-workers). I do a lot of stuff through Git, Grunt and the like so I’ve usually got a Cmder window open somewhere.
When using Git, there are a bunch of commands that I use frequently so it’s handy to have a shortcut to these.
DOSKEY is a Windows utility that adds things like command history (via up and down arrows) and macro functionality for Windows XP and beyond (and 9 as well).
It’s the macro functionality that we’ll be looking at.
DOSKEY Usage
To add a macro (alias for you Linux types) using DOSKEY, the syntax is just:
So, if we wanted to use gp instead of git pull, the command would be:
Viewing Existing Macros
If you’re using Cmder, you’ll already have some macros set up. You can view these (and any you’ve added) using:
Or, we can just add a macro to make it easier to remember:
Passing Parameters
For some macros, we’ll want to pass parameters through from the macro to the original command. This is done using $*.
Let’s say we wanted to create an alias for git log so we could call things like gl -5. This would look like:
Then we can call gl -5 to get the last 5 items.
Or, if we wanted to list commits in a custom format, we could do something like this:
This format then produces output like this:
Deleting a Macro
If you decide you want to delete a macro, it’s simply a case of setting the macro name to equal nothing:
Launching Apps
The last thing that I tend to use this for is launching various apps as needed.
Sublime Text
allows you to use
Notepad++
allows you to use:
Explorer
allows you to use:
to launch an explorer window in the current directory.
Go Play
So go and create some macros and let me know about any good ones you come up with.