mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-26 04:44:59 +00:00
feature: Open in selected default terminal.
This commit is contained in:
parent
8a255cd260
commit
26f2a1435a
3 changed files with 15 additions and 23 deletions
|
@ -117,8 +117,8 @@ namespace SourceGit.Native
|
||||||
public IReadOnlyList<Models.ExternalTerminal> FindExternalTerminals()
|
public IReadOnlyList<Models.ExternalTerminal> FindExternalTerminals()
|
||||||
{
|
{
|
||||||
var finder = new Models.ExternalTerminalFinder();
|
var finder = new Models.ExternalTerminalFinder();
|
||||||
finder.WindowsTerminal(() => FindExternalTerminal("wt"));
|
|
||||||
finder.WindowsGitBash(() => FindExternalTerminal("bash"));
|
finder.WindowsGitBash(() => FindExternalTerminal("bash"));
|
||||||
|
finder.WindowsTerminal(() => FindExternalTerminal("wt"));
|
||||||
finder.PowerShell(() => FindExternalTerminal("pwsh"));
|
finder.PowerShell(() => FindExternalTerminal("pwsh"));
|
||||||
return finder.Terminals;
|
return finder.Terminals;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
@ -296,7 +297,16 @@ namespace SourceGit.ViewModels
|
||||||
|
|
||||||
public void OpenInTerminal()
|
public void OpenInTerminal()
|
||||||
{
|
{
|
||||||
Native.OS.OpenTerminal(_fullpath);
|
var terminal = Native.OS.ExternalTerminals.FirstOrDefault(x => x.Name == Preference.Instance.DefaultTerminal)
|
||||||
|
?? Native.OS.ExternalTerminals.FirstOrDefault();
|
||||||
|
|
||||||
|
if (terminal is not null)
|
||||||
|
{
|
||||||
|
terminal.Open(_fullpath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
App.RaiseException(_fullpath, "No available external terminals found!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenWithExternalTool()
|
public void OpenWithExternalTool()
|
||||||
|
|
|
@ -263,7 +263,9 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
var iconKey = value is string terminalName && !string.IsNullOrWhiteSpace(terminalName) ?
|
var iconKey = value is string terminalName && !string.IsNullOrWhiteSpace(terminalName) ?
|
||||||
terminalName :
|
terminalName :
|
||||||
GetSystemDefaultTerminalIconKey();
|
OS.ExternalTerminals.FirstOrDefault()?.Name
|
||||||
|
// Impossible to be null, just a fallback.
|
||||||
|
?? "git-bash";
|
||||||
|
|
||||||
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalTerminalIcons/{iconKey}.png", UriKind.RelativeOrAbsolute));
|
var icon = AssetLoader.Open(new Uri($"avares://SourceGit/Resources/ExternalTerminalIcons/{iconKey}.png", UriKind.RelativeOrAbsolute));
|
||||||
return new Bitmap(icon);
|
return new Bitmap(icon);
|
||||||
|
@ -273,26 +275,6 @@ namespace SourceGit.Views
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetSystemDefaultTerminalIconKey()
|
|
||||||
{
|
|
||||||
if (OperatingSystem.IsWindows())
|
|
||||||
{
|
|
||||||
return "git-bash";
|
|
||||||
}
|
|
||||||
else if (OperatingSystem.IsMacOS())
|
|
||||||
{
|
|
||||||
return "osascript";
|
|
||||||
}
|
|
||||||
else if (OperatingSystem.IsLinux())
|
|
||||||
{
|
|
||||||
return "gnome-terminal";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new PlatformNotSupportedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public sealed class TerminalOrShellNameToLocalizedNameConverter : IValueConverter
|
public sealed class TerminalOrShellNameToLocalizedNameConverter : IValueConverter
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue