The following describes the steps to run a batch script that creates aliases using DOSKEY when opening command prompt. The batch file also creates an alias command that can be used to create aliases during the command line session.
Steps
- Create a Batch file with the commands
- Create shortcut that will run cmd with the batch file as input to the /k switch
Create a Batch file with the commands
- Open Notepad and copy the section between the markers and paste into notepadsave the file to %USERPROFILE%\cmdrc.cmd==== copy from @echo off to @echo on ====@echo offDOSKEY alias=if ".$*." == ".." ( DOSKEY /MACROS ) else ( DOSKEY $* )DOSKEY ls=DIR $*DOSKEY cp=COPY $*DOSKEY xcp=XCOPY $*DOSKEY mv=MOVE $*DOSKEY clear=CLSDOSKEY h=DOSKEY /HISTORYDOSKEY history=DOSKEY /HISTORY::compound commandsset REPOS=%USERPROFILE%\ReposDOSKEY repos=cd /d %REPOS%$Tdir /a:d /bDOSKEY waffle=cd /d %REPOS%$Tdir /a:d /b$Tcd waffle$Tdir /a:d $Tgit branchDOSKEY bw=cd /d %REPOS%$Twaffle-build.cmd@echo on==== copy from @echo off to @echo on ====
- Customise your shortcuts
- Place command separator as $T
- when you edit the cmdrc.cmd file run it again
- %USERPROFILE%\cmdrc.cmd
Create a Shortcut to run the resource file
- Open Windows Explorer and create a New Shortcut
- Open the Shortcut Properties
- Select the General Tab and Name the Shortcut e.g.
- DosKey Alias - Command Prompt
- Select the Shortcut Tab and set the Target
- %windir%\system32\cmd.exe /k %USERPROFILE%\cmdrc.cmd
Tips on using the new alias batch file
Place command separator as $T in usual batch as an && or ||
This line "DOSKEY repos=cd /d %USERPROFILE%\repos$Tdir /a:d" in the batch below
In the command prompt window; the execution flow will result in the following when USERPROFILE is c:\users\myusername\repos
1. change to the device C:
2. change to the directory to c:\users\myusername\repos
3. list directories only
Creating an alias
while in the command prompt is opened using the Target as described above, you can create alias using the alias command.
alias lsb=DIR /b $*
Testing the new alias
lsb c:\windows