mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-11-08 05:30:05 +01: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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user