1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 12:00:09 +02:00

🔧 Determine default shell based on macOS version

This fixes #21 (fixes the issue on Mojave) and closes #22 since the min
SDK does not need to be bumped.
This commit is contained in:
2021-02-19 17:28:50 +01:00
parent 79fbdef41b
commit d367f1f353
2 changed files with 20 additions and 6 deletions

View File

@ -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;

View File

@ -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()