Skip to content

Commit dccc249

Browse files
committed
Feature: Add 'Paths' command.
1 parent 1cf16f7 commit dccc249

File tree

6 files changed

+54
-12
lines changed

6 files changed

+54
-12
lines changed

G33kShell.Desktop/Terminal/Attributes/CommandType.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ public enum CommandType
1818
File,
1919
Navigation,
2020
System,
21-
Misc
21+
Misc,
22+
Hidden
2223
}

G33kShell.Desktop/Terminal/Commands/HelpCommand.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@ protected override Task<bool> Run(ITerminalState state)
2525
{
2626
var commands = Enum.GetValues<MyCommandType>()
2727
.Select(o => (GetCategory(o), CommandsHelper.GetCommandNames(o).ToArray().ToCsv(), CommandsHelper.GetCommandAttribute(o).Description))
28-
/*
29-
.Select(CommandsHelper.GetCommandAttribute)
30-
.OrderBy(o => o.LongName)
31-
.Select(o => (CommandsHelper.GetCommandNames(o).ToArray().ToCsv(), o.Description))
32-
.ToArray();
33-
*/
3428
.ToArray();
3529

3630
var maxLength = commands.Select(o => o.Item2.Length).Max();
3731
var isFirstLine = true;
38-
foreach (var category in commands.Select(o => o.Item1).Distinct())
32+
foreach (var category in commands.Select(o => o.Item1).Where(o => o != CommandType.Hidden).Distinct())
3933
{
4034
if (!isFirstLine)
4135
WriteLine();

G33kShell.Desktop/Terminal/Commands/MyCommandType.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
using G33kShell.Desktop.Terminal.Attributes;
1313
using NClap.Metadata;
14+
// ReSharper disable UnusedMember.Global
1415

1516
namespace G33kShell.Desktop.Terminal.Commands;
1617

@@ -88,19 +89,19 @@ public enum MyCommandType
8889
Clip,
8990

9091
[Command(typeof(ExitCommand), LongName = "exit", Description = "Quit the terminal.")]
91-
[CommandCategory(CommandType.System)]
92+
[CommandCategory(CommandType.Hidden)]
9293
Exit,
9394

9495
[Command(typeof(HelpCommand), LongName = "help", ShortName = "?", Description = "Get help information.")]
95-
[CommandCategory(CommandType.System)]
96+
[CommandCategory(CommandType.Hidden)]
9697
Help,
9798

9899
[Command(typeof(HistoryCommand), LongName = "history", Description = "List command history.")]
99100
[CommandCategory(CommandType.System)]
100101
History,
101102

102103
[Command(typeof(ManCommand), LongName = "man", Description = "Get usage information for a specific command.")]
103-
[CommandCategory(CommandType.System)]
104+
[CommandCategory(CommandType.Hidden)]
104105
Man,
105106

106107
[Command(typeof(MaxCommand), LongName = "max", Description = "Toggle the terminal window between maximized and restored states.")]
@@ -111,6 +112,10 @@ public enum MyCommandType
111112
[CommandCategory(CommandType.System)]
112113
Now,
113114

115+
[Command(typeof(PathsCommand), LongName = "paths", Description = "Lists all PATH entries alphabetically.")]
116+
[CommandCategory(CommandType.System)]
117+
Path,
118+
114119
[Command(typeof(ScreensaverCommand), LongName = "screensaver", Description = "Select and activate the screensaver.")]
115120
[CommandCategory(CommandType.System)]
116121
Screensaver,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Code authored by Dean Edis (DeanTheCoder).
2+
// Anyone is free to copy, modify, use, compile, or distribute this software,
3+
// either in source code form or as a compiled binary, for any non-commercial
4+
// purpose.
5+
//
6+
// If you modify the code, please retain this copyright header,
7+
// and consider contributing back to the repository or letting us know
8+
// about your modifications. Your contributions are valued!
9+
//
10+
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND.
11+
12+
using System;
13+
using System.IO;
14+
using System.Linq;
15+
using System.Threading.Tasks;
16+
using G33kShell.Desktop.Terminal.Attributes;
17+
18+
namespace G33kShell.Desktop.Terminal.Commands;
19+
20+
[CommandDescription("Lists all PATH entries alphabetically, marking any missing paths.")]
21+
public class PathsCommand : CommandBase
22+
{
23+
protected override Task<bool> Run(ITerminalState state)
24+
{
25+
var pathEntries = (Environment.GetEnvironmentVariable("PATH") ?? string.Empty)
26+
.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries)
27+
.Select(p => p.Trim())
28+
.Where(p => !string.IsNullOrWhiteSpace(p))
29+
.Distinct(StringComparer.OrdinalIgnoreCase)
30+
.OrderBy(p => p, StringComparer.OrdinalIgnoreCase)
31+
.ToArray();
32+
33+
foreach (var entry in pathEntries)
34+
{
35+
var info = new DirectoryInfo(entry);
36+
var prefix = info.Exists ? "[√] " : "[!] ";
37+
WriteLine($"{prefix}{entry}");
38+
}
39+
40+
return Task.FromResult(true);
41+
}
42+
}

G33kShell.Desktop/Views/App.axaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
using Avalonia.Controls;
1616
using Avalonia.Controls.ApplicationLifetimes;
1717
using Avalonia.Markup.Xaml;
18-
using Avalonia.Remote.Protocol.Input;
1918
using CSharp.Core.Extensions;
2019
using G33kShell.Desktop.Skins;
2120
using G33kShell.Desktop.Terminal;

G33kShell.sln.DotSettings.user

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADouble_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F97735572759ed38d9ce0373eff8d5c81728b76ebad7201de74c8191af042e_003FDouble_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
99
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ADriveType_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F787e459dfcbf4e599345a06d67315ac312c00_003F89_003F60d2c37c_003FDriveType_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1010
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnumerable_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0d7bcd21e5fc4d22acf66909cc56501684928_003F3c_003F054457f0_003FEnumerable_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
11+
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AEnvironment_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2025_002E1_003Fresharper_002Dhost_003FSourcesCache_003Fd5e26b7cbc3c8ffaa5eb6b56961c2ddefd21293d38d4a648eeb54d2d127492de_003FEnvironment_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1112
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFIGletFont_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0545674b691e481a8b2ad05064279b055a00_003F69_003F9878386c_003FFIGletFont_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1213
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFileInfo_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003Ff1cff5b88316fd138db54a5b97290ca7d973dfb75a74a45a2a5f0b9ae97e_003FFileInfo_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
1314
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003AFileSystemEnumerator_002EUnix_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003FLibrary_003FApplication_0020Support_003FJetBrains_003FRider2024_002E3_003Fresharper_002Dhost_003FSourcesCache_003F233863917bb42f133182fb4926e94ef8139c6f704da0c4574a8de3209f4761_003FFileSystemEnumerator_002EUnix_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>

0 commit comments

Comments
 (0)