2

I've installed Git for Windows, configured to use Git commands exclusively in Git Bash.

So I have a file composer.cmd sitting beside composer.phar which looks like this:

@echo off
php C:\bin\composer.phar %*

However, I still need to enter .cmd or .phar at the end of the command for it to see it. The extension .CMD exists in $PATHEXT but it doesn't seem to matter. Having to retype a command because I left off the extension breaks my rhythm, and it seems incredibly arbitrary that I'm able to run .exe files without the extensions.

I want to know if there's a way to coerce it into accepting that .cmd files do not need to have their extensions specified. And I'm not using the MSI package to install Composer.

Dissident Rage
  • 2,236
  • 1
  • 20
  • 30

2 Answers2

2

You need to create a new file in the same dir as composer.bat and just call it composer without extension. Include this line:

cmd "/C composer.bat $@"

After this the command should work from git bash:

composer -V
Jules Colle
  • 9,697
  • 7
  • 50
  • 59
0

Since a CMD session supports both .bat and .cmd, check if your same script could be called without extension while being named composer.bat

I know I can call my scripts (.bat) without .xxx

Bit from a git bash session, I need to add cmd /C:

git bash
cmd "/C myscript"
# or
cmd //c myscript

See:

myscript can be a myscript.bat, as long as it is in the Windows PATH, it will be executed.
And right after its execution, you are back in the git bash.

Or you could wrap the .bat/.cmd script in a shell script:

$ cat myscript.sh
cmd << EOD
myscript $@
EOD
$

In that case, a simple myscript would be enough.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283