mklement0/Native

`ie` can't call executables installed by Scoop

imgx64 opened this issue · 2 comments

I use Scoop to install command line programs on Windows. For each executable, Scoop creates two shims in ~/scoop/shims/: a .ps1 and an .exe. For example:

PS C:\> Get-Command -All git

CommandType     Name             Version    Source
-----------     ----             -------    ------
ExternalScript  git.ps1                     C:\Users\imgx64\scoop\shims\git.ps1
Application     git.exe          0.0.0.0    C:\Users\imgx64\scoop\shims\git.exe

If you try to run such shim with ie, it fails because the .ps1 has higher priority.

PS C:\> ie git --version
This command supports external executables (applications) only; "git" ("git.ps1") is a command of type ExternalScript
At C:\Users\imgx64\Documents\WindowsPowerShell\Modules\Native\1.0.3\Native.psm1:540 char:5
+     Throw (
+     ~~~~~~~
    + CategoryInfo          : InvalidArgument: (git:String) [], ArgumentException
    + FullyQualifiedErrorId : InvalidCommandType

Is it possible to detect this and run the .exe instead, without the user having to type .exe explicitly?

PS C:\> ie git.exe --version
git version 2.28.0.windows.1

Interesting suggestion, but I'd like to understand the purpose of the .ps1 shim better, and I'm generally concerned about bypassing PowerShell's command precedence.

The workaround is to use the .exe extension explicitly (though I get that it would be nicer without it):

ie git.exe --version

What is the purpose and benefit of the .ps1 shims?

I've just released 1.0.8, which fixes this problem:

It makes sense to have ie look only among external executables (command type Application), ignoring other command forms of the same name.