feature: try to read PATH from zsh

This commit is contained in:
leo 2024-10-14 16:58:29 +08:00
parent 1a4055ee97
commit a232f50755
No known key found for this signature in database
2 changed files with 26 additions and 9 deletions

View file

@ -195,15 +195,6 @@ namespace SourceGit.Commands
if (OperatingSystem.IsLinux())
start.Environment.Add("LANG", "en_US.UTF-8");
// Fix sometimes `LSEnvironment` not working on macOS
if (OperatingSystem.IsMacOS())
{
if (start.Environment.TryGetValue("PATH", out var path))
start.Environment.Add("PATH", $"/opt/homebrew/bin:/opt/homebrew/sbin:{path}");
else
start.Environment.Add("PATH", "/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin");
}
// Force using this app as git editor.
switch (Editor)
{

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.Versioning;
using System.Text;
using Avalonia;
@ -17,6 +18,31 @@ namespace SourceGit.Native
{
DisableDefaultApplicationMenuItems = true,
});
{
var startInfo = new ProcessStartInfo();
startInfo.FileName = "zsh";
startInfo.Arguments = "--login -c \"echo $PATH\"";
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.StandardOutputEncoding = Encoding.UTF8;
try
{
var proc = new Process() { StartInfo = startInfo };
proc.Start();
var pathData = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
if (proc.ExitCode == 0)
Environment.SetEnvironmentVariable("PATH", pathData);
proc.Close();
}
catch
{
// Ignore error.
}
}
}
public string FindGitExecutable()