Skip to content

Commit 059a616

Browse files
author
Staffan Gustafsson
committed
Binary SelectEverythingString
1 parent d015177 commit 059a616

2 files changed

Lines changed: 44 additions & 34 deletions

File tree

PSEverything/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
// by using the '*' as shown below:
3636
// [assembly: AssemblyVersion("1.0.*")]
3737
[assembly: AssemblyVersion("1.0.0.0")]
38-
[assembly: AssemblyFileVersion("2.0.0.0")]
38+
[assembly: AssemblyFileVersion("2.2.0.0")]

PSEverything/SelectEverythingStringCommand.cs

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System.Linq;
22
using System.Management.Automation;
33
using Microsoft.PowerShell.Commands;
4+
using System.Collections;
5+
using System.Collections.Generic;
46

57
namespace PSEverything
68
{
@@ -9,6 +11,22 @@ namespace PSEverything
911
[Alias("sles")]
1012
public class SelectEverythingStringCommand : PSCmdlet
1113
{
14+
static readonly string[] SearchParamNames = new[]{
15+
"CaseSensitive",
16+
"ChildFileName",
17+
"Exclude",
18+
"Extension",
19+
"Filter",
20+
"FolderExclude",
21+
"FolderInclude",
22+
"Global",
23+
"Include",
24+
"MatchWholeWord",
25+
"NameLength",
26+
"ParentCount",
27+
"PathExclude",
28+
"PathInclude",
29+
"RegularExpression" };
1230
[Parameter(Mandatory = true, Position = 1)]
1331
public string[] Pattern { get; set; }
1432
[Parameter]
@@ -77,44 +95,36 @@ public class SelectEverythingStringCommand : PSCmdlet
7795
[Parameter(ParameterSetName = "default")]
7896
public SwitchParameter MatchWholeWord { get; set; }
7997

80-
98+
8199
protected override void EndProcessing()
82100
{
83-
var searchEverything = new SearchEverythingCommand()
101+
var searchParams = new Dictionary<string, object>(SearchParamNames.Length)
84102
{
85-
AsArray = true,
86-
CaseSensitive = CaseSensitiveSearch,
87-
ChildFileName = ChildFileName,
88-
Exclude = Exclude,
89-
Extension = Extension,
90-
Filter = Filter,
91-
FolderExclude = FolderExclude,
92-
FolderInclude = FolderExclude,
93-
Global = Global,
94-
Include = Include,
95-
MatchWholeWord = MatchWholeWord,
96-
NameLength = NameLength,
97-
ParentCount = ParentCount,
98-
PathExclude = PathExclude,
99-
PathInclude = PathInclude,
100-
RegularExpression = RegularExpression,
103+
{ "AsArray", true }
101104
};
102-
var paths= searchEverything.Invoke<string[]>().FirstOrDefault();
103-
var selectStringCommand = new SelectStringCommand()
105+
var bound = MyInvocation.BoundParameters;
106+
foreach (var sp in SearchParamNames)
104107
{
105-
LiteralPath = paths,
106-
Pattern = Pattern,
107-
AllMatches = AllMatches,
108-
CaseSensitive = CaseSensitivePattern,
109-
Context = Context,
110-
Encoding = Encoding,
111-
List = List,
112-
NotMatch = NotMatch,
113-
Quiet = Quiet,
114-
SimpleMatch = SimpleMatch
115-
};
116-
WriteObject(selectStringCommand.Invoke<MatchInfo>(), true);
117-
108+
if (bound.TryGetValue(sp, out object val))
109+
{
110+
searchParams.Add(sp, val);
111+
bound.Remove(sp);
112+
}
113+
}
114+
115+
var slsParams = bound;
116+
117+
var ps = PowerShell.Create(RunspaceMode.CurrentRunspace);
118+
ps.AddCommand("Search-Everything").AddParameters(searchParams);
119+
var paths = ps.Invoke<string[]>().FirstOrDefault();
120+
if (paths == null)
121+
{
122+
return;
123+
}
124+
125+
ps.Commands.Clear();
126+
ps.AddCommand("Select-String").AddParameter("LiteralPath", paths).AddParameters(slsParams);
127+
WriteObject(ps.Invoke(), true);
118128
}
119129
}
120130
}

0 commit comments

Comments
 (0)