From d367f1f353313edd146e9e5da57d195f83f1890a Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Fri, 19 Feb 2021 17:28:50 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Determine=20default=20shell=20ba?= =?UTF-8?q?sed=20on=20macOS=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes #21 (fixes the issue on Mojave) and closes #22 since the min SDK does not need to be bumped. --- PHP Monitor.xcodeproj/project.pbxproj | 4 ++-- phpmon/Domain/Terminal/Shell.swift | 22 ++++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/PHP Monitor.xcodeproj/project.pbxproj b/PHP Monitor.xcodeproj/project.pbxproj index 1f540a7..919e70e 100644 --- a/PHP Monitor.xcodeproj/project.pbxproj +++ b/PHP Monitor.xcodeproj/project.pbxproj @@ -577,7 +577,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 45; + CURRENT_PROJECT_VERSION = 46; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; @@ -601,7 +601,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 45; + CURRENT_PROJECT_VERSION = 46; DEVELOPMENT_TEAM = 8M54J5J787; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = phpmon/Info.plist; diff --git a/phpmon/Domain/Terminal/Shell.swift b/phpmon/Domain/Terminal/Shell.swift index c6ed5c1..aeb5de5 100644 --- a/phpmon/Domain/Terminal/Shell.swift +++ b/phpmon/Domain/Terminal/Shell.swift @@ -15,12 +15,26 @@ class Shell { Shell.user.run(command) } - public static func pipe(_ command: String, shell: String = "/bin/sh") -> String { - Shell.user.pipe(command, shell: shell) + public static func pipe(_ command: String) -> String { + Shell.user.pipe(command) } // MARK: - Singleton + var shell = "/bin/sh" + + init() { + // Determine if we're using macOS Catalina or newer (that support /bin/zsh as default shell) + let supportsZsh = ProcessInfo.processInfo.isOperatingSystemAtLeast( + .init(majorVersion: 10,minorVersion: 15,patchVersion: 0)) + + // If macOS Mojave is being used, we'll default to /bin/bash + if (!supportsZsh) { + print("You're not running macOS Catalina or newer, so defaulting to /bin/bash!") + self.shell = "/bin/bash" + } + } + /** Singleton to access a user shell (with --login) */ @@ -43,11 +57,11 @@ class Shell { - Parameter command: The command to run - Parameter shell: Path to the shell to invoke */ - func pipe(_ command: String, shell: String = "/bin/sh") -> String { + func pipe(_ command: String) -> String { let task = Process() let pipe = Pipe() - task.launchPath = shell + task.launchPath = self.shell task.arguments = ["--login", "-c", command] task.standardOutput = pipe task.launch()