Skip to content

Search cygpath.exe from Git's install path #2641

@hyrious

Description

@hyrious

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions