Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3 from gbraad/override-shell
Browse files Browse the repository at this point in the history
  • Loading branch information
cerebrate committed Feb 19, 2021
2 parents 5e15afb + ef5b630 commit a93aafd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
56 changes: 45 additions & 11 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;

#endregion

Expand Down Expand Up @@ -75,6 +77,29 @@ string InvokeWslpath (string path)
throw new InvalidOperationException (message: "What the path is this?");
}

private static IConfiguration Configuration {

get
{
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("$.json", true, false)
.Build();
return config;
}
}

private static string Shell
{
get
{
string shell = Configuration["shell"];
if(shell == null || shell.Equals(String.Empty)) {
shell = "sh";
}
return shell;
}
}

private static void PrintHelp ()
{
ConsoleColor oldColor = Console.ForegroundColor;
Expand Down Expand Up @@ -105,18 +130,27 @@ private static int Main (string[] args)

try
{
// Check through arguments, one by one.
var param = new List<string> ();

foreach (var arg in args)

// Identify those which are probably Windows paths.
// And perform path translation.
param.Add (item: Program.IsWindowsPath (arg: arg) ? Program.TranslatePath (path: arg) : arg);
string shell = Program.Shell;

Process ps;
if(args.Length == 0) {
// No arguments given
ps = Process.Start (fileName: "wsl",
arguments: $"-e genie -c {shell}");
} else {
// Check through arguments, one by one.
var param = new List<string> ();

foreach (var arg in args)
// Identify those which are probably Windows paths.
// And perform path translation.
param.Add (item: Program.IsWindowsPath (arg: arg) ? Program.TranslatePath (path: arg) : arg);

// Execute in WSL.
ps = Process.Start (fileName: "wsl",
arguments: $"-e genie -c {shell} -c \"{string.Join (separator: ' ', values: param)}\"");
}

// Execute in WSL.
Process ps = Process.Start (fileName: "wsl",
arguments: $"-e genie -c sh -c \"{string.Join (separator: ' ', values: param)}\"");

ps.WaitForExit ();

Expand Down
5 changes: 4 additions & 1 deletion RunInGenie.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
<SelfContained>false</SelfContained>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
</ItemGroup>
</Project>

0 comments on commit a93aafd

Please sign in to comment.