restores Helder in all its glory

This commit is contained in:
2026-09-28 11:34:49 +02:00
parent c2b38b853c
commit 1d29d0952d
280 changed files with 29205 additions and 7 deletions
@@ -0,0 +1,38 @@
import Foundation
/// Finds command-line tools for a GUI app, whose PATH is only /usr/bin:/bin:/usr/sbin:/sbin.
public struct ExecutableLocator: Sendable {
/// Directories searched in order.
public var directories: [String]
public init(directories: [String]) {
self.directories = directories
}
/// The app's own Helpers folder (where bundle.sh puts ripgrep), then PATH, then Homebrew.
public static var standard: ExecutableLocator {
var dirs: [String] = []
dirs.append(Bundle.main.bundleURL.appendingPathComponent("Contents/Helpers").path)
let path = ProcessInfo.processInfo.environment["PATH"] ?? "/usr/bin:/bin:/usr/sbin:/sbin"
dirs += path.split(separator: ":").map(String.init)
dirs += ["/opt/homebrew/bin", "/usr/local/bin"]
var seen = Set<String>()
return ExecutableLocator(directories: dirs.filter { seen.insert($0).inserted })
}
/// The first executable file called `name`, or nil. A name with a slash is checked as given.
public func locate(_ name: String) -> URL? {
let fm = FileManager.default
if name.contains("/") {
return fm.isExecutableFile(atPath: name) ? URL(fileURLWithPath: name) : nil
}
for dir in directories {
let candidate = (dir as NSString).appendingPathComponent(name)
var isDir: ObjCBool = false
if fm.fileExists(atPath: candidate, isDirectory: &isDir), !isDir.boolValue, fm.isExecutableFile(atPath: candidate) {
return URL(fileURLWithPath: candidate)
}
}
return nil
}
}