diff --git a/src/Models/ExternalMergeTools.cs b/src/Models/ExternalMergeTools.cs index 5fb4300b..6efd6471 100644 --- a/src/Models/ExternalMergeTools.cs +++ b/src/Models/ExternalMergeTools.cs @@ -30,6 +30,17 @@ namespace SourceGit.Models { new ExternalMergeTools(3, "KDiff3", "/Applications/kdiff3.app/Contents/MacOS/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), new ExternalMergeTools(4, "Beyond Compare 4", "/Applications/Beyond Compare.app/Contents/MacOS/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), }; + } else if (OperatingSystem.IsLinux()) { + Supported = new List() { + new ExternalMergeTools(0, "Custom", "", "", ""), + new ExternalMergeTools(1, "Visual Studio Code", "/usr/share/code/code", "-n --wait \"$MERGED\"", "-n --wait --diff \"$LOCAL\" \"$REMOTE\""), + new ExternalMergeTools(2, "KDiff3", "/usr/bin/kdiff3", "\"$REMOTE\" -b \"$BASE\" \"$LOCAL\" -o \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + new ExternalMergeTools(3, "Beyond Compare 4", "/usr/bin/bcomp", "\"$REMOTE\" \"$LOCAL\" \"$BASE\" \"$MERGED\"", "\"$LOCAL\" \"$REMOTE\""), + }; + } else { + Supported = new List() { + new ExternalMergeTools(0, "Custom", "", "", ""), + }; } } diff --git a/src/Native/Linux.cs b/src/Native/Linux.cs new file mode 100644 index 00000000..009bed42 --- /dev/null +++ b/src/Native/Linux.cs @@ -0,0 +1,73 @@ +using System.Diagnostics; +using System.IO; +using System.Runtime.Versioning; + +namespace SourceGit.Native { + [SupportedOSPlatform("linux")] + internal class Linux : OS.IBackend { + public string FindGitExecutable() { + if (File.Exists("/usr/bin/git")) return "/usr/bin/git"; + return string.Empty; + } + + public string FindVSCode() { + if (File.Exists("/usr/share/code/code")) return "/usr/share/code/code"; + return string.Empty; + } + + public void OpenBrowser(string url) { + if (!File.Exists("/usr/bin/xdg-open")) { + App.RaiseException("", $"You should install xdg-open first!"); + return; + } + + Process.Start("xdg-open", $"\"{url}\""); + } + + public void OpenInFileManager(string path, bool select) { + if (!File.Exists("/usr/bin/xdg-open")) { + App.RaiseException("", $"You should install xdg-open first!"); + return; + } + + if (Directory.Exists(path)) { + Process.Start("xdg-open", $"\"{path}\""); + } else { + var dir = Path.GetDirectoryName(path); + if (Directory.Exists(dir)) { + Process.Start("xdg-open", $"\"{dir}\""); + } + } + } + + public void OpenTerminal(string workdir) { + var dir = string.IsNullOrEmpty(workdir) ? "~" : workdir; + if (File.Exists("/usr/bin/gnome-ternimal")) { + Process.Start("/usr/bin/gnome-ternimal", $"--working-directory=\"{dir}\""); + } else if (File.Exists("/usr/bin/konsole")) { + Process.Start("/usr/bin/konsole", $"--workdir \"{dir}\""); + } else if (File.Exists("/usr/bin/xfce4-terminal")) { + Process.Start("/usr/bin/xfce4-terminal", $"--working-directory=\"{dir}\""); + } else { + App.RaiseException("", $"Only supports gnome-ternimal/konsole/xfce4-terminal!"); + return; + } + } + + public void OpenWithDefaultEditor(string file) { + if (!File.Exists("/usr/bin/xdg-open")) { + App.RaiseException("", $"You should install xdg-open first!"); + return; + } + + var proc = Process.Start("xdg-open", $"\"{file}\""); + proc.WaitForExit(); + + if (proc.ExitCode != 0) { + App.RaiseException("", $"Failed to open \"{file}\""); + } + + proc.Close(); + } + } +} diff --git a/src/Native/OS.cs b/src/Native/OS.cs index 7af3ef48..c73c7eb3 100644 --- a/src/Native/OS.cs +++ b/src/Native/OS.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.IO; namespace SourceGit.Native { public static class OS { @@ -31,6 +30,9 @@ namespace SourceGit.Native { } else if (OperatingSystem.IsWindows()) { _backend = new Windows(); VSCodeExecutableFile = _backend.FindVSCode(); + } else if (OperatingSystem.IsLinux()) { + _backend = new Linux(); + VSCodeExecutableFile = _backend.FindVSCode(); } else { throw new Exception("Platform unsupported!!!"); }