Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the logic to allow terminal emulators to be installed outside /usr/bin #752

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/MICore/TerminalLauncher.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check seems invalid now, unless you are checking /usr/bin/.

I think the proper thing should be to short circuit it with a /usr/bin/ and if it isn't there, then allow it to search path.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, only but it's customary to maintain a backward compatibility 😂

{
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<EnvironmentEntry> 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);
Expand Down