-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCdCommand.cs
More file actions
34 lines (29 loc) · 871 Bytes
/
CdCommand.cs
File metadata and controls
34 lines (29 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.IO;
using NShell.Shell;
using NShell.Shell.Commands;
using Spectre.Console;
namespace NShell.Commands;
public class CdCommand : ICustomCommand
{
public string Name => "cd";
public void Execute(ShellContext context, string[] args)
{
if (args.Length == 0)
{
AnsiConsole.MarkupLine("[[[yellow]*[/]]] - Usage: cd <directory>");
return;
}
string target = args[0];
string fullPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), target));
if (Directory.Exists(fullPath))
{
Directory.SetCurrentDirectory(fullPath);
context.CurrentDirectory = fullPath;
}
else
{
AnsiConsole.MarkupLine($"[[[red]-[/]]] - No such directory: {fullPath}");
}
}
}