HOME
Stephen Knight
11/04/2011 02:46 PM
Adding unix like aliases to Windows CMD prompt

Type:

Batch/Command file

Category:

Firstly --> These scripts and entries are partly taken from the links below so not claiming they are all mine, though wish I had thought of using the alias doskey macro below!

This adds a new autorun entry so that when you open a command prompt it runs a batch file called macros.cmd. This is then used to run each time a doskey command to pickup a list of aliases stored in a file called doskey.mac in your user profile directory (or of course you can change all the paths if you wish).

The doskey macros is a good way of making one short command run a longer one, or to add shortcuts for commands such as "ls" when people are prone to using the Unix shell type commands.

The alias command defined here as one of the doskey macros allow you to amend the aliases from the command prompt a follows:

Alias - shows aliases
alias SAVE -- records current aliases to doskey.mac file
alias LOAD -- load aliases back from file
alias anything else gets passed to doskey command line,

e.g.

alias ls=dir
alias lsl=dir /w
alias SAVE

See code area below for the changes to make:

Hide details for CodeCode
Add a new AutoRun registry entry for the command prompt as follows:

HKEY_CURRENT_USER\Software\Microsoft\Command Processor
new --> string value called AutoRun
with value %userprofile%\macros.cmd

or save these three lines below as a .REG file in notepad and then double click it to run it from explorer:

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]
"AutoRun"="%userprofile%\\macros.cmd"

In Start | Run enter:

notepad "%Userprofile%\macros.cmd"

and put this one line in and save:

@doskey /macrofile="%userprofile%\doskey.mac"

Then create the macros file:
notepad "%Userprofile%\doskey.mac"
and enter:

alias=IF "$*" == "" (doskey /macros) ELSE (IF /I "$1" == "SAVE" (doskey /macros $g "%USERPROFILE%\doskey.mac" & ECHO Aliases SAVED) ELSE (IF /I "$1"=="LOAD" (doskey /macrofile="%USERPROFILE%\doskey.mac" & ECHO Aliases LOADED & doskey /macros) ELSE (doskey $*)))
ls=dir
cat=type

Launch a cmd.exe and try it... I just did and seems to work nicely.


Hide details for ExplanationExplanation
Show details for ExamplesExamples
Hide details for AttachmentsAttachments