Wednesday, January 9, 2013

Windows command line aliases

As a former part time Ubuntu user I used a lot of alias definitions for often used shell commands. I missed the alias utility on windows but found that the windows doskey utility is a fair enough alternative for me.

I most often use doskey in the form

doskey <MacroName>=[<Text>]
"Creates a macro that carries out the commands specified by Text. MacroName specifies the name you want to assign to the macro. Text specifies the commands you want to record." (from Windows doskey reference as linked above)
The [<Text>] parameter supports some useful special characters like

$T     separates commands
$1-$9  batch parameter placeholder

I put all my doskey definitions in a batch file (myCmd.bat) which I use to start a new command line window.

This works pretty well for me - and maybe also for you. You will find a myCmd.bat example shown below.


@echo off
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
rem quick directory access aliases
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
doskey ..=cd ..
doskey ...=cd ..\..
doskey cdprogs=c:$Tcd c:\progs
doskey cdjetty=c:$Tcd C:\progs\jetty-6.1.21
doskey cdtomcat=c:$Tcd c:\progs\apache-tomcat-7.0.32
doskey cdeclipse=c:$Tcd C:\progs\eclipse
doskey cdhome=cd %HOMEPATH%
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
rem start & stop glassfish which hosts wiki
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
doskey startwiki=C:\progs\glassfishv3\bin\asadmin start-domain
doskey stopwiki=C:\progs\glassfishv3\bin\asadmin stop-domain
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
rem start & stop other server that I just
rem unzipped instead of installed
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
doskey starttomcat=c:\progs\apache-tomcat-7.0.32\bin\startup.bat
doskey startsonar=c:\progs\sonar-2.10\bin\windows-x86-32\StartSonar.bat
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
rem Maven aliases
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
doskey mvnci=mvn -DskipTests clean install
doskey mvncd=mvn clean deploy
doskey mvnddu=mvn versions:display-dependency-updates
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
rem alias related aliases ;-)
rem +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
doskey editconfig=notepad c:\progs\myCmd.bat
doskey alias=doskey /macros
rem keep the command line tool open
cmd /K
@echo on
view raw myCmd.bat hosted with ❤ by GitHub