1
1
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:
Tae Won Ha 2018-08-17 12:10:59 +02:00
parent 8e362111d3
commit 01a7f119ee
No known key found for this signature in database
GPG Key ID: E40743465B5B8B44

View File

@ -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]
}
}
}
}