Skip to content

Commit 4e29c74

Browse files
committed
add hostname and ls commands
1 parent cf41849 commit 4e29c74

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

hostname.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.IO;
2+
using System.Net;
3+
using ILeoConsole;
4+
using ILeoConsole.Plugin;
5+
using ILeoConsole.Core;
6+
7+
namespace LeoConsole_ExamplePlugin {
8+
public class Hostname : ICommand {
9+
public string Name { get { return "hostname"; } }
10+
public string Description { get { return "print computer's hostname"; } }
11+
public Action CommandFunktion { get { return () => Command(); } }
12+
private string[] _InputProperties;
13+
public string[] InputProperties { get { return _InputProperties; } set { _InputProperties = value; } }
14+
15+
public void Command() {
16+
Console.WriteLine(Dns.GetHostName());
17+
}
18+
}
19+
}
20+
21+
// vim: tabstop=2 softtabstop=2 shiftwidth=2 expandtab

ls.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.IO;
2+
using ILeoConsole;
3+
using ILeoConsole.Plugin;
4+
using ILeoConsole.Core;
5+
6+
namespace LeoConsole_ExamplePlugin {
7+
public class Ls : ICommand {
8+
public string Name { get { return "ls"; } }
9+
public string Description { get { return "list contents of a folder"; } }
10+
public Action CommandFunktion { get { return () => Command(); } }
11+
private string[] _InputProperties;
12+
public string[] InputProperties { get { return _InputProperties; } set { _InputProperties = value; } }
13+
public IData data = new ConsoleData();
14+
15+
public void Command() {
16+
if (_InputProperties.Length < 2) {
17+
ls(data.SavePath);
18+
return;
19+
}
20+
for (int i = 1; i < _InputProperties.Length; i++) {
21+
ls(_InputProperties[i]);
22+
Console.Write("\n");
23+
}
24+
}
25+
26+
private void ls(string directory) {
27+
Console.WriteLine(directory + ":");
28+
try {
29+
foreach (string filename in Directory.GetDirectories(directory)) {
30+
Console.WriteLine(Path.GetFileName(filename) + "/");
31+
}
32+
foreach (string filename in Directory.GetFiles(directory)) {
33+
Console.WriteLine(Path.GetFileName(filename));
34+
}
35+
} catch (Exception e) {
36+
Console.WriteLine("error: " + e.Message);
37+
}
38+
}
39+
}
40+
}
41+
42+
// vim: tabstop=2 softtabstop=2 shiftwidth=2 expandtab

plugin.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ public void PluginMain() {
2929

3030
_Commands = new List<ICommand>();
3131
_Commands.Add(new Basename());
32+
_Commands.Add(new Cat());
3233
_Commands.Add(new Clear());
3334
_Commands.Add(new Echo());
35+
_Commands.Add(new Hostname());
36+
_Commands.Add(new Ls());
3437
_Commands.Add(new Yes());
35-
_Commands.Add(new Cat());
3638
}
3739
}
3840
}

0 commit comments

Comments
 (0)