Console aliases in Windows – the better approach

A big advantage of working in console mode is ability to create aliases. First you can easily shorten a command with a lot of switches. You can also automate your job by creating a script file and then set an alias for that script.

The default way of creating aliases in Windows is DOSKEY:

doskey np=notepad++.exe $*

The weak point of it is that you have to reassign them after restarting console window. There are ways for automating that using cmd.exe /k switch or using system
registry (see both article and comments).

There is also a buil-in option for ConEmu:

But all in all this is weak, as always you have to do two things: establish an
alias and then save it in some file for future use.

Alternative (better!) solution

I can sell you my way of dealing with aliases. I don’t use DOSKEY. Instead, I have a folder, i.e. C:\Tools\Aliases and there. I have a lot of *.cmd or *.ps1 files. The trick is that the folder is in my PATH variable.
Let’s say I have there a !notes.cmd command that runs:

vim c:\documents\notes01.txt

Then I can type ‘!notes’ and it runs “!notes.cmd” file that results in openning my temporary notes file. Obviously TAB autocompletion works fine. ‘!’ in the beginning lets me filter out my own aliases. I have also “!editaliases.cmd” for editing my aliases:

vim c:\tools\aliases\

Aliases are ready to use just after adding/editing them.
Other advantages:

  • no fancy escape characters (doskey defines its own list)
  • I can assing a whole script to an alias with one file
  • works in every console and emulator

3 thoughts on “Console aliases in Windows – the better approach

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s