Shell/Bash tasks in Windows using the task runner #48
-
Hi there, I've been struggling to try to some Shell/Bash tasks to work in Windows. To start with, I had this configured:
{
"tasks": [
]
}
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
sh --version Wish was working in I then tried to see if I could move the
#!/bin/sh
sh --version
{
"tasks": [
{
"name": "display-version",
"group": "pre-commit",
"cwd": ".husky",
"command": "bash",
"args": [ "-c", "display-version.sh" ]
}
]
}
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
dotnet husky run But when committing in It makes sense since Bash isn't available in a Windows environment. But I'm wondering how it's working when I inline the script within Is there any way I can define tasks that will allow them to run like they do when inlined in An alternative solution I was playing around with was trying to see if I could run my When I try to write an equivalent like so:
{
"tasks": [
{
"name": "display-version",
"group": "pre-commit",
"cwd": ".husky",
"command": "cmd",
"args": [ "/c", "%PROGRAMFILES%\\Git\\bin\\sh.exe", "display-version.sh" ]
}
]
} I get an error message like: I've tried many different ways of putting the In any case, I would really like to use tasks and the task runner. But at the moment, I'm stuck having to inline my Shell/Bash tasks within the hooks like Any feedback is appreciated! Thanks 😀. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Unfortunately
private var shPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) , @"git\bin\sh.exe" );
private var startInfo = new ProcessStartInfo(shPath, "display-version.sh");
Process.Start(startInfo);
|
Beta Was this translation helpful? Give feedback.
Hi @Eric-Bonneau
Unfortunately
Process.Start
in Dotnet doesn't support this format (%PROGRAMFILES%
) that's why you can not pass this value, but for now, you have a few workarounds to access sh.exe:C:\Program Files\Git\bin
to your system environment PATH, this way sh.exe would be available through cmd. (also there is an option for this during git installation)C:\Program Files\Git\bin\sh.exe
instead of%PROGRAMFILES%\...