Skip to content

Commit 8d07b07

Browse files
committed
Other: Improve cdd command matching by prioritizing exact case-insensitive matches.
1 parent 2d4030c commit 8d07b07

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

G33kShell.Desktop/Terminal/Commands/CddCommand.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// about your modifications. Your contributions are valued!
99
//
1010
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
11+
12+
using System;
1113
using System.IO;
1214
using System.Linq;
1315
using System.Threading.Tasks;
@@ -34,15 +36,24 @@ protected override Task<bool> Run(ITerminalState state)
3436
.Select(o => (o, GetScore(o, Path)))
3537
.OrderByDescending(o => o.Item2)
3638
.ToArray();
37-
var result = candidates.FirstOrDefault();
39+
40+
// Check for a perfect match.
41+
var result = candidates.FirstOrDefault(o => System.IO.Path.GetFileName(o.o)?.Equals(Path, StringComparison.OrdinalIgnoreCase) == true);
42+
43+
// ...failing that, find the best match.
44+
if (result.Item2 == 0.0)
45+
result = candidates.FirstOrDefault();
46+
3847
if (result.Item2 > 0.7)
3948
{
49+
// Good enough to be a likely match - Use it.
4050
var newDir = result.o.ToDir();
4151
state.CurrentDirectory = newDir;
4252
Settings.Instance.AppendPathToHistory(newDir.FullName);
4353
return Task.FromResult(true);
4454
}
4555

56+
// Not enough info - Report what matches _might_ exist.
4657
if (candidates.Any())
4758
{
4859
WriteLine("Candidates:");

0 commit comments

Comments
 (0)