-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSSHToProfileConverter.cs
48 lines (44 loc) · 1.52 KB
/
SSHToProfileConverter.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Serilog;
namespace SSHMan
{
public static class SSHToProfileConverter
{
public static (bool,string) GenerateSettings(string file)
{
if(!File.Exists(file)) {
Log.Warning("Skipped terminal settings update because '{file}' doesn't exist", file);
return (false,string.Empty); // If the file doesn't exist that's okay
}
var json = File.ReadAllText(file);
var cfg = TerminalConfig.FromJson(json);
var hosts = SSHParser.MapHosts();
if (cfg.Profiles.HasValue)
{
var profileMaster = cfg.Profiles.Value;
var profiles = profileMaster.ProfilesObject;
foreach (var host in hosts)
{
var name = $"{host.Key} (SSH)";
if (profiles.List.Any((x) => x.Name == name))
{
continue;
}
var list = new ProfileList()
{
Guid = "{" + Guid.NewGuid().ToString() + "}",
Commandline = $"ssh {host.Key}",
Name = name,
CloseOnExit = CloseOnExitEnum.Always
};
profiles.List.Add(list);
}
cfg.Profiles = profiles;
}
return (true,cfg.ToJson());
}
}
}