Modify how Doskey macro passes arguments to the command based on arguments passed to it

I have a farily simple doskey macro

DOSKEY s="C:\Program Files (x86)\Git\bin\sh.exe" --login

So I could switch from command prompt to git shell by s

But sometimes I only want to execute a single command in shell and return to command line. For that I either have to enter shell, do stuff, exit. Or I could modify the doskey macro

DOSKEY s="C:\Program Files (x86)\Git\bin\sh.exe" --login -c "$*"

But that would mean I can't use it to do the former now, i.e enter shell, it's for executing only now.

I was wondering if I could have it conditionally choose between the two based on whether or not I have passed it another argument. So s would do the former, but s echo hello would do the latter.

Is there a way to do this?


Solution 1:

You can use any standard CMD.EXE commands within your macro definition. The IF command can test if you have at least one paramater passed and branch accordingly.

doskey s=if $1. equ . ("C:\Program Files (x86)\Git\bin\sh.exe" --login) else "C:\Program Files (x86)\Git\bin\sh.exe" --login -c "$*"