Skip to content

Commit

Permalink
Wox.Plugin.Shell now supports bash on Windows 10 #1308
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeppLu authored and bao-qian committed Apr 21, 2020
1 parent c0c6f8e commit dec7252
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Plugins/Wox.Plugin.Shell/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,24 @@ private ProcessStartInfo PrepareProcessStartInfo(string command, bool runAsAdmin
info = ShellCommand.SetProcessStartInfo(command, verb: runAsAdministratorArg);
}
}
else if (_settings.Shell == Shell.Bash && _settings.SupportWSL)
{
string arguments;
if (_settings.LeaveShellOpen)
{
// FIXME: How to deal with commands containing single quote?
arguments = $"-c \'{command} ; $SHELL\'";
}
else
{
arguments = $"-c \'{command} ; echo -n Press any key to exit... ; read -n1\'";
}
info = new ProcessStartInfo
{
FileName = "bash.exe",
Arguments = arguments
};
}
else
{
throw new NotImplementedException();
Expand Down
21 changes: 19 additions & 2 deletions Plugins/Wox.Plugin.Shell/Settings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.IO;
using System.Collections.Generic;

namespace Wox.Plugin.Shell
{
Expand All @@ -10,6 +12,21 @@ public class Settings
public bool RunAsAdministrator { get; set; } = true;

public Dictionary<string, int> Count = new Dictionary<string, int>();
public bool SupportWSL { get; private set; }

public Settings()
{
try
{
string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string wslRoot = localAppData + @"\lxss\rootfs";
SupportWSL = Directory.Exists(wslRoot);
}
catch
{
SupportWSL = false;
}
}

public void AddCmdHistory(string cmdName)
{
Expand All @@ -29,6 +46,6 @@ public enum Shell
Cmd = 0,
Powershell = 1,
RunCommand = 2,

Bash = 3
}
}
4 changes: 4 additions & 0 deletions Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ private void CMDSetting_OnLoaded(object sender, RoutedEventArgs re)
};

ShellComboBox.SelectedIndex = (int) _settings.Shell;
if (_settings.SupportWSL)
{
ShellComboBox.Items.Add("Bash");
}
ShellComboBox.SelectionChanged += (o, e) =>
{
_settings.Shell = (Shell) ShellComboBox.SelectedIndex;
Expand Down

0 comments on commit dec7252

Please sign in to comment.