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

👌 Add source_php{version} helpers

This commit is contained in:
2022-03-17 21:21:05 +01:00
parent 25c7004368
commit c43e00c88d

View File

@ -146,9 +146,52 @@ class PhpEnv {
} }
} }
writeHelpers(with: output)
return output return output
} }
private func writeHelpers(with versions: [String]) {
for version in versions {
do {
let resolve = "\(Paths.optPath)/php@\(version)/bin"
let path = URL(fileURLWithPath: resolve).resolvingSymlinksInPath().path
let dotless = version.replacingOccurrences(of: ".", with: "")
try! FileManager.default.createDirectory(
at: URL(fileURLWithPath: "/Users/\(Paths.whoami)/.local/phpmon"),
withIntermediateDirectories: true
)
let sourcePath = "/Users/\(Paths.whoami)/.local/phpmon/source_php\(dotless)"
let source = """
export PATH=\(path):$PATH
"""
try source.write(
to: URL(fileURLWithPath: sourcePath),
atomically: true,
encoding: String.Encoding.utf8
)
let script = """
#!/bin/zsh
[[ $ZSH_EVAL_CONTEXT =~ :file$ ]] \\
&& echo "PHP Monitor has enabled this terminal to use PHP \(version)." \\
|| echo "You must run '. pm\(dotless)' (or 'source pm\(dotless)') instead!";
source ~/.local/phpmon/source_php\(dotless);
"""
let alias = "/usr/local/bin/pm\(dotless)"
try script.write(
to: URL(fileURLWithPath: alias),
atomically: true,
encoding: String.Encoding.utf8
)
Shell.run("chmod +x \(sourcePath)")
Shell.run("chmod +x \(path)")
} catch {
print(error)
Log.err("Could not write PHP Monitor helper for PHP \(version) to /usr/local/bin")
}
}
}
public func validVersions(for constraint: String) -> [PhpVersionNumber] { public func validVersions(for constraint: String) -> [PhpVersionNumber] {
constraint.split(separator: "|").flatMap { constraint.split(separator: "|").flatMap {
return PhpVersionNumberCollection return PhpVersionNumberCollection