Skip to content

Commit

Permalink
work around zsh PATH resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilken committed Jan 10, 2024
1 parent a0ab61d commit 789669a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Nautik Helper.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = io.nautik.Nautik.Helper;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -370,7 +370,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 14.0;
MARKETING_VERSION = 1.0.1;
MARKETING_VERSION = 1.0.2;
PRODUCT_BUNDLE_IDENTIFIER = io.nautik.Nautik.Helper;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down
11 changes: 7 additions & 4 deletions Nautik Helper/StoredCluster.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class StoredCluster: Codable, @unchecked Sendable {

if let exec = authInfo.exec {
try await Task.detached { [weak self] in
guard let stdout = try? executeCommand(command: exec.command, arguments: exec.args) else {
guard let stdout = try executeCommand(command: exec.command, arguments: exec.args) else {
throw "Executing \(exec.command) yielded no stdout."
}

Expand Down Expand Up @@ -160,12 +160,15 @@ func executeCommand(command: String, arguments: [String]? = nil) throws -> Strin
guard let shell = try runProcess(command: "/usr/bin/env", arguments: ["/bin/sh", "-cl", "echo $SHELL"]) else {
throw "Couldn't evaluate the user's SHELL."
}

if try runProcess(command: "/usr/bin/env", arguments: [shell, "-cl", "eval $(/usr/libexec/path_helper -s) && which \(command)"]) == nil {

guard let cmdPath = try runProcess(command: "/usr/bin/env", arguments: [shell, "-cl\(shell.contains("zsh") ? "i" : "")", "which \(command)"]) else {
throw "Executable \(command) not found in the user's PATH."
}
if cmdPath == "\(command) not found" {
throw "Executable \(command) not found in the user's PATH."
}

let stdout = try runProcess(command: "/usr/bin/env", arguments: [shell, "-cl", "eval $(/usr/libexec/path_helper -s) && \(command) \(arguments.map { $0.joined(separator: " ") } ?? "")"])
let stdout = try runProcess(command: "/usr/bin/env", arguments: [shell, "-cl", "\(cmdPath) \(arguments.map { $0.joined(separator: " ") } ?? "")"])

return stdout

Expand Down

0 comments on commit 789669a

Please sign in to comment.