From 8d4ac072ba9adeb972afd110d58a55c838cb1c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=9D=E6=AD=8C?= Date: Mon, 13 Aug 2018 16:58:42 +0800 Subject: [PATCH] Update TerminalLauncher.cs Modify the logic to allow terminal emulators to be installed outside `/usr/bin` --- src/MICore/TerminalLauncher.cs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/MICore/TerminalLauncher.cs b/src/MICore/TerminalLauncher.cs index 9473169f5..0261b450f 100644 --- a/src/MICore/TerminalLauncher.cs +++ b/src/MICore/TerminalLauncher.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft. All rights reserved. +// Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; @@ -168,20 +168,36 @@ protected override void SetNewProcessEnvironment(ProcessStartInfo processStartIn internal class LinuxTerminalLauncher : TerminalLauncher { - private const string GnomeTerminalPath = "/usr/bin/gnome-terminal"; - private const string XTermPath = "/usr/bin/xterm"; + private const string GnomeTerminalPath = "gnome-terminal"; + private const string XTermPath = "xterm"; private string _terminalPath; private string _bashCommandPrefix; + private bool ExistInPath(string fileName) + { + if (File.Exists(fileName)) + { + return true; + } + foreach (var path in Environment.GetEnvironmentVariable("PATH").Split(':')) + { + if (File.Exists(Path.Combine(path, fileName))) + { + return true; + } + } + return false; + } + public LinuxTerminalLauncher(string title, string initScript, ReadOnlyCollection environment) : base(title, initScript, environment) { - if (File.Exists(GnomeTerminalPath)) + if (ExistInPath(GnomeTerminalPath)) { _terminalPath = GnomeTerminalPath; _bashCommandPrefix = String.Format(CultureInfo.InvariantCulture, "--title {0} --", _title); } - else if (File.Exists(XTermPath)) + else if (ExistInPath(XTermPath)) { _terminalPath = XTermPath; _bashCommandPrefix = String.Format(CultureInfo.InvariantCulture, "-title {0} -e", _title);