Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select-EverythingString should not pass directories to Select-String #7

Open
nightroman opened this issue Jun 6, 2022 · 0 comments

Comments

@nightroman
Copy link

nightroman commented Jun 6, 2022

This is not necessarily a bug but a nuisance that hopefully may be avoided with a tweak.
The steps to reproduce in Windows PowerShell console, e.g. v5.1:

  • change to this repository root directory
  • invoke
Select-EverythingString Search-Everything

As a result, the command emits errors like:

Microsoft.PowerShell.Utility\Select-String : The file ...\PSEverything\.git
cannot be read: Access to the path '...\PSEverything\.git' is denied.
At line:1 char:1
+ Select-EverythingString Search-Everything
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Select-String], ArgumentException
    + FullyQualifiedErrorId : ProcessingFile,Microsoft.PowerShell.Commands.SelectStringCommand

Presumably this happens because the underlying Search-Everything gets and
passes all file system entry paths to Select-String, including folders.
Select-String does not like input directory paths in v5.1.

NOTE: The same command works without errors in PowerShell Core.
Perhaps Select-String learned to ignore directory paths.

I am thinking of the fix of SelectEverythingStringCommand.cs like:

    if (searchParams.TryGetValue(nameof(Filter), out var filterValue))
    {
        searchParams[nameof(Filter)] = "file:" + filterValue;
    }
    else
    {
        searchParams.Add(nameof(Filter), "file:");
    }

With the above we tell Search-Everything to return just files, so that
Select-String is happy in any PowerShell.

If you find the suggested fix reasonable and a PR is welcome I can take care of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant