mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-07 03:50:08 +02:00
🐛 Resolve issue with determining PATH (#194)
In previous builds, PHP Monitor would use interactive mode when opening a /bin/zsh shell, in order to be able to load the full PATH. This is a problem because when launching PHP Monitor via the command line or when you have some interactivity in an actual interactive shell, it is possible to get stuck waiting for a particular input which will effectively 'freeze' PHP Monitor's shell. There are two options to fix this: 1) work with a timeout, which may or may not return a PATH 2) use a non-interactive shell and source .zshrc I chose option 2, which is the more robust choice. If no .zshrc file exists, it is also not sourced to avoid warnings or errors from ending up in the PATH.
This commit is contained in:
@ -14,12 +14,18 @@ extension Shell {
|
||||
let task = Process()
|
||||
task.launchPath = "/bin/zsh"
|
||||
|
||||
// We need an interactive shell so the user's PATH is loaded in correctly
|
||||
task.arguments = ["--login", "-ilc", "echo $PATH"]
|
||||
let command = Filesystem.fileExists("~/.zshrc")
|
||||
// source the user's .zshrc file if it exists to complete $PATH
|
||||
? ". ~/.zshrc && echo $PATH"
|
||||
// otherwise, non-interactive mode is sufficient
|
||||
: "echo $PATH"
|
||||
|
||||
task.arguments = ["--login", "-lc", command]
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
task.launch()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
|
||||
return String(data: data, encoding: String.Encoding.utf8) ?? ""
|
||||
|
Reference in New Issue
Block a user