httptoolkit / httptoolkit-server

The backend of HTTP Toolkit

Home Page:https://httptoolkit.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fresh Terminal, Wrong git-bash

jonathansampson opened this issue · comments

One issue others may find is that HTTP Toolkit fails to open a New Terminal Window. In my case, the wrong git-bash command/file was being located. To identify which, I ran Get-Command git-bash in Powershell and found that an unexpected batch file was being accessed instead of my git-bash.exe.

To resolve the issue, I made sure my Git directory (C:\Program Files\Git in my case) was added to the Environment Variables, and positioned earlier than the directory which held the batch file with a similar name. This resolved the issue, enabling HTTP Toolkit to locate the proper executable.

const getWindowsTerminalCommand = async (): Promise<SpawnArgs | null> => {
if (await commandExists('git-bash')) {
return { command: 'git-bash' };
} else if (await canAccess(DEFAULT_GIT_BASH_PATH)) {
return { command: DEFAULT_GIT_BASH_PATH };
}
return { command: 'start', args: ['cmd'], options: { shell: true }, skipStartupScripts: true };
};

The project presently uses command-exists, which only checks where. The lookpath project takes a slightly more rigorous approach, determining whether the path is an executable:

Thanks for filing this @jonathansampson!

I've got a very quick fix in place already: 246a044.

That'll work for this exact situation, by prioritising normal git-bash installs over random things in your $PATH. There's all sorts of other edge cases though (e.g. git-bash in PATH but not actually installed at all) so I do intend to harden this up further. It's not released yet, but that'll go out in the next server update.

The project presently uses command-exists, which only checks where. The lookpath project takes a slightly more rigorous approach, determining whether the path is an executable:

This is a very good point! I'll take a look at lookpath and see if I can use that to filter this down further, and maybe get a perf boost if I can avoid lots of spawning too.

I'd also like to get "Existing Terminal" working on Windows, eventually, which'll help with this. On Linux and Mac, you can use that and copy a bash command into a terminal to intercept any terminal, so launch heuristics don't matter so much. On Windows that's difficult though: most terminals aren't bash-compatible, and git bash & WSL transforms all the file paths which makes it complicated to generate the right env vars.

Preferring the default bash path is a great change. Thanks!

Just to let you know - the fix above and the switch over to lookpath was released recently, which should help with this. Thanks for the report & suggestions!

HTTP Toolkit will update automatically in the background next time you use it, and then everything will work as expected. I'm going to close this issue for now since that resolves the immediate problem, but let me know if you see any other issues in future.