From 94329678b23158a3a243952449ba420e5f676a54 Mon Sep 17 00:00:00 2001 From: Zepp Lu Date: Sat, 18 Mar 2017 13:43:07 +0800 Subject: [PATCH] Wox.Plugin.Shell now supports bash on Windows 10 --- Plugins/Wox.Plugin.Shell/Main.cs | 18 ++++++++++++++++ Plugins/Wox.Plugin.Shell/Settings.cs | 21 +++++++++++++++++-- Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs | 4 ++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Plugins/Wox.Plugin.Shell/Main.cs b/Plugins/Wox.Plugin.Shell/Main.cs index 1a5174c4e..cd2367bab 100644 --- a/Plugins/Wox.Plugin.Shell/Main.cs +++ b/Plugins/Wox.Plugin.Shell/Main.cs @@ -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(); diff --git a/Plugins/Wox.Plugin.Shell/Settings.cs b/Plugins/Wox.Plugin.Shell/Settings.cs index af149e829..8e84c31bf 100644 --- a/Plugins/Wox.Plugin.Shell/Settings.cs +++ b/Plugins/Wox.Plugin.Shell/Settings.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.IO; +using System.Collections.Generic; namespace Wox.Plugin.Shell { @@ -10,6 +12,21 @@ public class Settings public bool RunAsAdministrator { get; set; } = true; public Dictionary Count = new Dictionary(); + 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) { @@ -29,6 +46,6 @@ public enum Shell Cmd = 0, Powershell = 1, RunCommand = 2, - + Bash = 3 } } diff --git a/Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs b/Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs index ffa3b5856..69c4f2621 100644 --- a/Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs +++ b/Plugins/Wox.Plugin.Shell/ShellSetting.xaml.cs @@ -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;