mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
refactor: detect terminal before it is needed
This commit is contained in:
parent
f4f5ae7430
commit
04a187203a
1 changed files with 10 additions and 13 deletions
|
@ -14,15 +14,10 @@ namespace SourceGit.Native
|
||||||
{
|
{
|
||||||
enum TerminalType
|
enum TerminalType
|
||||||
{
|
{
|
||||||
Terminal,
|
Default,
|
||||||
iTerm2,
|
iTerm2,
|
||||||
}
|
}
|
||||||
|
|
||||||
public MacOS()
|
|
||||||
{
|
|
||||||
_terminal = Directory.Exists("/Applications/iTerm.app") ? TerminalType.iTerm2 : TerminalType.Terminal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetupApp(AppBuilder builder)
|
public void SetupApp(AppBuilder builder)
|
||||||
{
|
{
|
||||||
builder.With(new MacOSPlatformOptions()
|
builder.With(new MacOSPlatformOptions()
|
||||||
|
@ -33,7 +28,6 @@ namespace SourceGit.Native
|
||||||
|
|
||||||
public string FindGitExecutable()
|
public string FindGitExecutable()
|
||||||
{
|
{
|
||||||
// XCode built-in git
|
|
||||||
return File.Exists("/usr/bin/git") ? "/usr/bin/git" : string.Empty;
|
return File.Exists("/usr/bin/git") ? "/usr/bin/git" : string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,22 +51,19 @@ namespace SourceGit.Native
|
||||||
public void OpenInFileManager(string path, bool select)
|
public void OpenInFileManager(string path, bool select)
|
||||||
{
|
{
|
||||||
if (Directory.Exists(path))
|
if (Directory.Exists(path))
|
||||||
{
|
|
||||||
Process.Start("open", $"\"{path}\"");
|
Process.Start("open", $"\"{path}\"");
|
||||||
}
|
|
||||||
else if (File.Exists(path))
|
else if (File.Exists(path))
|
||||||
{
|
|
||||||
Process.Start("open", $"\"{path}\" -R");
|
Process.Start("open", $"\"{path}\" -R");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public void OpenTerminal(string workdir)
|
public void OpenTerminal(string workdir)
|
||||||
{
|
{
|
||||||
var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir;
|
var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir;
|
||||||
dir = dir.Replace(" ", "\\ ");
|
dir = dir.Replace(" ", "\\ ");
|
||||||
|
|
||||||
|
var terminal = DetectTerminal();
|
||||||
var cmdBuilder = new StringBuilder();
|
var cmdBuilder = new StringBuilder();
|
||||||
switch (_terminal)
|
switch (terminal)
|
||||||
{
|
{
|
||||||
case TerminalType.iTerm2:
|
case TerminalType.iTerm2:
|
||||||
cmdBuilder.AppendLine("on run argv");
|
cmdBuilder.AppendLine("on run argv");
|
||||||
|
@ -109,6 +100,12 @@ namespace SourceGit.Native
|
||||||
Process.Start("open", $"\"{file}\"");
|
Process.Start("open", $"\"{file}\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly TerminalType _terminal;
|
private TerminalType DetectTerminal()
|
||||||
|
{
|
||||||
|
if (Directory.Exists("/Applications/iTerm.app"))
|
||||||
|
return TerminalType.iTerm2;
|
||||||
|
|
||||||
|
return TerminalType.Default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue