Skip to content

Commit f6ce545

Browse files
BornToBeRootclaude
andcommitted
Feature: Recently run profiles first in the run command suggestions
The recent commands are not shown while typing a profile ("@"), so the profiles of the command are ordered by their last use within the same rank (exact name, starts with, contains). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 1ff098d commit f6ce545

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

‎Source/NETworkManager/ViewModels/RunCommandViewModel.cs‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ public class RunCommandViewModel : ViewModelBase
3636
private readonly Action<RunCommandViewModel> _runHandler;
3737

3838
/// <summary>
39-
/// Recent commands with their command (parsed once, the history doesn't change while the dialog is open).
39+
/// Recent commands with their command and profile name (parsed once, the history doesn't change while the dialog
40+
/// is open).
4041
/// </summary>
41-
private readonly List<(string Text, RunCommandDefinition Command)> _history;
42+
private readonly List<(string Text, RunCommandDefinition Command, string ProfileName)> _history;
4243

4344
/// <summary>
4445
/// Names (command and aliases) and translated name per command.
@@ -71,8 +72,10 @@ public RunCommandViewModel(Action<RunCommandViewModel> runHandler, Action<RunCom
7172
// Entries of commands that are not available anymore (e.g. a hidden application) are not shown.
7273
_history =
7374
[
74-
.. SettingsManager.Current.RunCommand_History.Select(x => (x, RunCommandParser.Parse(x, _commands).Command))
75-
.Where(x => x.Command != null)
75+
.. SettingsManager.Current.RunCommand_History
76+
.Select(x => (Text: x, Result: RunCommandParser.Parse(x, _commands)))
77+
.Where(x => x.Result.Command != null)
78+
.Select(x => (x.Text, x.Result.Command, x.Result.ProfileName))
7679
];
7780

7881
CancelCommand = new RelayCommand(_ => cancelHandler(this));
@@ -372,7 +375,8 @@ private IEnumerable<RunCommandSuggestion> GetCommandSuggestions()
372375
}
373376

374377
/// <summary>
375-
/// Profiles of the command that match the typed profile name (or target).
378+
/// Profiles of the command that match the typed profile name (or target). Recently run profiles of the command
379+
/// come first within the same rank, since the recent commands are not shown while typing a profile ("@").
376380
/// </summary>
377381
private IEnumerable<RunCommandSuggestion> GetProfileSuggestions()
378382
{
@@ -401,11 +405,22 @@ private IEnumerable<RunCommandSuggestion> GetProfileSuggestions()
401405
_profiles[_result.Command] = profiles;
402406
}
403407

408+
// Position of the profile name in the history of the command (most recent first)
409+
var recentProfileNames = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
410+
411+
foreach (var entry in _history.Where(x => x.Command == _result.Command && !string.IsNullOrEmpty(x.ProfileName)))
412+
recentProfileNames.TryAdd(entry.ProfileName, recentProfileNames.Count);
413+
414+
// The name is compared like it is parsed (without surrounding whitespace and quotes).
415+
int GetRecentIndex(ProfileInfo profile) =>
416+
recentProfileNames.GetValueOrDefault(profile.Name.Trim().Trim('"').Trim(), int.MaxValue);
417+
404418
return profiles
405419
.Select(x => (Profile: x, Target: x.GetTarget(application)))
406420
.Select(x => (x.Profile, x.Target, Rank: GetRank(x.Profile, x.Target, text)))
407421
.Where(x => x.Rank != null)
408422
.OrderBy(x => x.Rank)
423+
.ThenBy(x => GetRecentIndex(x.Profile))
409424
.Select(x => new RunCommandSuggestion
410425
{
411426
Kind = RunCommandSuggestionKind.Profile,

‎Website/docs/run-command.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ While typing, suggestions are shown below the input:
7070
| Command (e.g. `tr`) | Matching features |
7171
| After the command (`rdp `) | The input as typed, recent commands of the feature and its profiles |
7272
| After `lookup ` | The input as typed, the lookups (`oui`, `port`) and recent commands |
73-
| `@` (e.g. `rdp @web`) | Profiles of the feature (with group and host); exact names first |
73+
| `@` (e.g. `rdp @web`) | Profiles of the feature (with group and host); exact names first, recently run profiles first within the same match |
7474
| After the target | The input as typed, types of the feature (e.g. DNS record types), configured DNS servers (DNS lookup) and recent commands |
7575

7676
`Enter` runs what was typed: after the command, the input as typed is the first suggestion; profiles, recent commands, types and DNS servers are selected with the arrow keys. While typing the command, the best matching feature is selected (completing it keeps the arguments, e.g. `pin 10.0.0.1` → `ping 10.0.0.1`), but not if the input is empty or an unknown command has arguments. While typing `@`, a profile is only selected if exactly one matches. While typing the lookup (e.g. `lookup po`), the matching lookup is selected.

0 commit comments

Comments
 (0)