3

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.

2 Answers 2

5

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
Sign up to request clarification or add additional context in comments.

2 Comments

I suppose it's better to use cmd //C composer.bat $@. Otherwise you might get something like Command "update --lock" is not defined if you use composer update --lock for example.
and using a symlink to composer.phar might do as well. Would prefer this if symlinks are enabled.
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.

2 Comments

I tried that, Git Bash still requires the extension.
@DissidentRage OK. I have edited the answer to propose some workaround.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.