Nuke.Cola
Loading...
Searching...
No Matches
EverythingGlobbing.cs
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Runtime.Versioning;
5using System.Threading.Tasks;
6using EverythingSearchClient;
7using Nuke.Common.IO;
8
10
11[SupportedOSPlatform("windows")]
13{
14 readonly SearchClient _everything = new();
15
16 public int Priority => 0;
17
18 private Result Glob(AbsolutePath root, string pattern)
19 {
20 var absolutePattern = (root / pattern).ToString();
21
22 // Nuke globbing **/ includes starting directory of recursion however Everything only starts
23 // recursion with subdirectories. In order to emulate Nuke globbing we repeat the pattern
24 // **/ excluded
25 var processedPattern = absolutePattern.Contains("**/") || absolutePattern.Contains("**\\")
26 ? absolutePattern + "|" + absolutePattern.Replace("**/", "").Replace("**\\", "")
27 : absolutePattern;
28
29 return _everything.Search(
30 processedPattern,
31 SearchClient.SearchFlags.MatchPath | SearchClient.SearchFlags.MatchWholeWord,
32 SearchClient.BehaviorWhenBusy.WaitOrContinue
33 );
34 }
35
36 public IEnumerable<AbsolutePath> GlobFiles(AbsolutePath root, string pattern)
37 => Glob(root, pattern).Items
38 .Where(i => i.Flags == Result.ItemFlags.None)
39 .Select(i => ((AbsolutePath) i.Path) / i.Name);
40
41 public IEnumerable<AbsolutePath> GlobDirectories(AbsolutePath root, string pattern)
42 => Glob(root, pattern).Items
43 .Where(i => i.Flags == Result.ItemFlags.Folder)
44 .Select(i => ((AbsolutePath) i.Path) / i.Name);
45}
Simple interface for swapping file search engines.