Not many people seem to know about it, but you can use the doskey
built-in macro tool, the only issue is that it doesn't save. There are many ways to work around this though.
usage:
doskey ls=dir
ls
will now do a directory listing just like dir
would.
If you want to use arguments with the commands, use this syntax:
doskey d=dir $*
As for the workaround to make them save:
- save all aliases to a file in this format:
doskey ls=dir
doskey ..=cd ..
and place it in one of the directories in your path. Name it something short like a.cmd, so when you open cmd you can type a to load your aliases.
If typing an a and pressing Enter seems too much work, throw this into your AutoHotkey script:
WinWaitActive, C:\WINDOWS\system32\cmd.exe
Send {a}{Enter}
Loading aliases automatically:
You can change all shortcuts to cmd to point to %SystemRoot%\system32\cmd.exe /K C:\path\to\aliases.cmd
, replacing C:\path\to\aliases.cmd
with the location of your aliases file. If you typically run it from the run box, you can:
- Rename the cmd executable to cmd2.exe for example, and replace it with a script or another executable which launches the above command (I wouldn't really recommend this method as a lot of apps depend on cmd)
- Make a batch script and call it cmda (cmd with aliases) for example. Have it launch the above command and put this batch script somewhere in your path.
Best Answer
See edited section of the question: This works absolutely fine (with terminal closed etc):