Skip to content

Commit c3e1fb9

Browse files
committed
refactor: fix maxOS PATH env
Signed-off-by: leo <[email protected]>
1 parent c8bee2f commit c3e1fb9

File tree

4 files changed

+14
-19
lines changed

4 files changed

+14
-19
lines changed

src/Commands/Command.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,6 @@ private ProcessStartInfo CreateGitStartInfo()
198198
start.Environment.Add("LC_ALL", "C");
199199
}
200200

201-
// Fix macOS `PATH` env
202-
if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv))
203-
start.Environment.Add("PATH", Native.OS.CustomPathEnv);
204-
205201
// Force using this app as git editor.
206202
switch (Editor)
207203
{

src/Commands/ExecuteCustomAction.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ public static void Run(string repo, string file, string args)
1717
start.CreateNoWindow = true;
1818
start.WorkingDirectory = repo;
1919

20-
// Fix macOS `PATH` env
21-
if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv))
22-
start.Environment.Add("PATH", Native.OS.CustomPathEnv);
23-
2420
try
2521
{
2622
Process.Start(start);
@@ -44,10 +40,6 @@ public static void RunAndWait(string repo, string file, string args, Action<stri
4440
start.StandardErrorEncoding = Encoding.UTF8;
4541
start.WorkingDirectory = repo;
4642

47-
// Fix macOS `PATH` env
48-
if (OperatingSystem.IsMacOS() && !string.IsNullOrEmpty(Native.OS.CustomPathEnv))
49-
start.Environment.Add("PATH", Native.OS.CustomPathEnv);
50-
5143
var proc = new Process() { StartInfo = start };
5244
var builder = new StringBuilder();
5345

src/Native/MacOS.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,22 @@ public void SetupApp(AppBuilder builder)
1818
DisableDefaultApplicationMenuItems = true,
1919
});
2020

21+
// Fix `PATH` env on macOS.
22+
var path = Environment.GetEnvironmentVariable("PATH");
23+
if (string.IsNullOrEmpty(path))
24+
path = "/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
25+
else if (!path.Contains("/opt/homebrew/", StringComparison.Ordinal))
26+
path = "/opt/homebrew/bin:/opt/homebrew/sbin:" + path;
27+
2128
var customPathFile = Path.Combine(OS.DataDir, "PATH");
2229
if (File.Exists(customPathFile))
23-
OS.CustomPathEnv = File.ReadAllText(customPathFile).Trim();
30+
{
31+
var env = File.ReadAllText(customPathFile).Trim();
32+
if (!string.IsNullOrEmpty(env))
33+
path = env;
34+
}
35+
36+
Environment.SetEnvironmentVariable("PATH", path);
2437
}
2538

2639
public string FindGitExecutable()

src/Native/OS.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ public static string DataDir
3131
private set;
3232
} = string.Empty;
3333

34-
public static string CustomPathEnv
35-
{
36-
get;
37-
set;
38-
} = string.Empty;
39-
4034
public static string GitExecutable
4135
{
4236
get => _gitExecutable;

0 commit comments

Comments
 (0)