just icon indicating copy to clipboard operation
just copied to clipboard

Search cygpath.exe from Git's install path

Open hyrious opened this issue 10 months ago • 2 comments

I was trying the Shebang Recipes function and got this error:

C:\Users\hyrious\Desktop\Sakuna>just ruby
error: Could not find `cygpath` executable to translate recipe `ruby` shebang interpreter path:
program not found

This was because I do not have cygpath in my PATH. I do have cygpath.exe in the installation directory of Git and MSYS2, but they are not added to PATH for not polluting my normal shell. For example, PowerShell would prefer echo.exe (from bash) over the echo command, they behave differently obviously.

While the most complete solution may be quite complex regarding to #1549 and #2599. I have a more trivial feature request that, just can search for cygpath.exe from common paths like a relative path to Git:

C:\Users\hyrious\Desktop\Sakuna>C:\progra~1\Git\usr\bin\cygpath --version
cygpath (cygwin) 3.4.10
Path Conversion Utility
Copyright (C) 1998 - 2024 Cygwin Authors
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

C:\Users\hyrious\Desktop\Sakuna>C:\progra~1\Git\usr\bin\cygpath ruby
ruby

The basic logic is as follows:

  1. See if C:\progra~1\Git\usr\bin\cygpath.exe exists. This is the default location that Git for Windows will be installed at. It is highly possible that there's a cygpath.exe.

  2. If not, search for git.exe by where git or simply iterating over the PATH environment.

  3. If git exists, resolve the cygpath by join(git_path, '../../usr/bin/cygpath.exe').

    > fs.existsSync(path.join(String.raw`C:\Progra~1\Git\cmd\git.exe`, '../../usr/bin/cygpath.exe'))
    true
    

You're free to choose not to implement that.

hyrious avatar Feb 26 '25 16:02 hyrious

I think I probably wouldn't want to try to guess where cygpath.exe is. However, we could add a command line flag --cygpath which takes the path to the cygpath.exe executable. This would be kind of annoying, since you would have to do just --cygpath FOO every time you invoked just, except all command line flags are configureable with environment variables, so you could set JUST_CYGPATH=FOO in your environment and you wouldn't have to add the flag.

casey avatar Feb 27 '25 01:02 casey

I think this would be pretty straightforward, so adding the "good first issue" tag in case anyone wants to take a crack at it.

casey avatar Feb 27 '25 01:02 casey