From 789669a4761287f0900c77791210da5973e685b0 Mon Sep 17 00:00:00 2001 From: Elias Wilken Date: Wed, 10 Jan 2024 21:51:56 +0100 Subject: [PATCH] work around zsh PATH resolution --- Nautik Helper.xcodeproj/project.pbxproj | 4 ++-- Nautik Helper/StoredCluster.swift | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Nautik Helper.xcodeproj/project.pbxproj b/Nautik Helper.xcodeproj/project.pbxproj index 7cb8de7..a9dd6d4 100644 --- a/Nautik Helper.xcodeproj/project.pbxproj +++ b/Nautik Helper.xcodeproj/project.pbxproj @@ -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; @@ -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; diff --git a/Nautik Helper/StoredCluster.swift b/Nautik Helper/StoredCluster.swift index 8562cc1..414f66b 100644 --- a/Nautik Helper/StoredCluster.swift +++ b/Nautik Helper/StoredCluster.swift @@ -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." } @@ -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