Search code examples
gitcomposer-phpmsysgit

Git Bash and Composer - Running without an extension


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.


Solution

  • 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