mirror of
https://github.com/qvacua/vimr.git
synced 2024-12-24 22:33:52 +03:00
GH-664 Extract env vars correctly
This commit is contained in:
parent
8e362111d3
commit
01a7f119ee
@ -19,7 +19,8 @@ class ProcessUtils {
|
||||
shellArgs.append("-i")
|
||||
}
|
||||
|
||||
shellArgs.append(contentsOf: ["-c", "env"])
|
||||
let marker = UUID().uuidString
|
||||
shellArgs.append(contentsOf: ["-c", "echo \(marker) && env"])
|
||||
|
||||
let outputPipe = Pipe()
|
||||
let errorPipe = Pipe()
|
||||
@ -41,11 +42,16 @@ class ProcessUtils {
|
||||
process.terminate()
|
||||
process.waitUntilExit()
|
||||
|
||||
return output
|
||||
guard let range = output.range(of: marker) else {
|
||||
return [:]
|
||||
}
|
||||
|
||||
return output[range.upperBound...]
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.split(separator: "\n")
|
||||
.reduce(into: [:]) { result, entry in
|
||||
let split = entry.split(separator: "=", maxSplits: 1, omittingEmptySubsequences: false).map { String($0) }
|
||||
result[split[0]] = split[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user