Skip to content

Instantly share code, notes, and snippets.

@amynbe
Last active February 15, 2024 14:25
Show Gist options
  • Save amynbe/c521bd9d22eb138a5810269a4a639c96 to your computer and use it in GitHub Desktop.
Save amynbe/c521bd9d22eb138a5810269a4a639c96 to your computer and use it in GitHub Desktop.
Cygwin shebang path converter
#!/bin/sh
# This allows you to run shebang-based scripts in Cygwin with tools that
# require Windows paths, like the Windows build of python or the kotlin
# interpreter.
# put this file in /usr/local/bin/ and use it as a shebang like this:
# #!/usr/local/bin/wenv myWindowsTool.exe
if [ $# -eq 1 ]
then
env $1
else
env $1 `cygpath -m -- $2` "${@:3}" ;
fi
@raboehm
Copy link

raboehm commented Feb 15, 2024

Thank you for this. $# is always >1, so "then" is not executed. The test should check for a non-cygwin location. For example, I put windows python in ~/local/python311c.

#!/bin/sh
if [[ "$(which ${1%% *})" =~ "local/python31" ]] ; then
    env -S $1 `cygpath -m -- $2` "${@:3}" ;
else
    env -S "${@}"
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment