mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
♻️ Change default shell for commands, cleanup files
The shell that is now invoked is /bin/sh as opposed to /bin/bash, which has proven to be faster in various cases.
This commit is contained in:
@ -10,8 +10,7 @@ import Cocoa
|
|||||||
|
|
||||||
extension Date
|
extension Date
|
||||||
{
|
{
|
||||||
func toString() -> String
|
func toString() -> String {
|
||||||
{
|
|
||||||
let dateFormatter = DateFormatter()
|
let dateFormatter = DateFormatter()
|
||||||
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
|
||||||
return dateFormatter.string(from: self)
|
return dateFormatter.string(from: self)
|
||||||
|
@ -10,13 +10,18 @@ import Foundation
|
|||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
func countInstances(of stringToFind: String) -> Int {
|
func countInstances(of stringToFind: String) -> Int {
|
||||||
assert(!stringToFind.isEmpty)
|
if (stringToFind.isEmpty) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
var count = 0
|
var count = 0
|
||||||
var searchRange: Range<String.Index>?
|
var searchRange: Range<String.Index>?
|
||||||
|
|
||||||
while let foundRange = range(of: stringToFind, options: [], range: searchRange) {
|
while let foundRange = range(of: stringToFind, options: [], range: searchRange) {
|
||||||
count += 1
|
count += 1
|
||||||
searchRange = Range(uncheckedBounds: (lower: foundRange.upperBound, upper: endIndex))
|
searchRange = Range(uncheckedBounds: (lower: foundRange.upperBound, upper: endIndex))
|
||||||
}
|
}
|
||||||
|
|
||||||
return count
|
return count
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,27 +24,4 @@ class Command {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func experiment() {
|
|
||||||
/*
|
|
||||||
print("Running '/usr/local/bin/php -v' directly...")
|
|
||||||
print("========================================")
|
|
||||||
var start = DispatchTime.now()
|
|
||||||
print(Command.execute(path: "/usr/local/bin/php", arguments: ["-v"]))
|
|
||||||
var end = DispatchTime.now()
|
|
||||||
var nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds
|
|
||||||
var timeInterval = Double(nanoTime) / 1_000_000_000
|
|
||||||
print("Time to run command directly: \(timeInterval) seconds")
|
|
||||||
|
|
||||||
print("")
|
|
||||||
print("Running 'bash -> php -v'...")
|
|
||||||
print("========================================")
|
|
||||||
start = DispatchTime.now()
|
|
||||||
print(Shell.user.pipe("php -v"))
|
|
||||||
end = DispatchTime.now()
|
|
||||||
nanoTime = end.uptimeNanoseconds - start.uptimeNanoseconds
|
|
||||||
timeInterval = Double(nanoTime) / 1_000_000_000
|
|
||||||
print("Time to run command via bash: \(timeInterval) seconds")
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,9 @@ class Shell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Runs a shell command and returns the output.
|
/// Runs a shell command and returns the output.
|
||||||
public func pipe(_ command: String) -> String {
|
public func pipe(_ command: String, shell: String = "/bin/sh") -> String {
|
||||||
let task = Process()
|
let task = Process()
|
||||||
task.launchPath = "/bin/bash"
|
task.launchPath = shell
|
||||||
task.arguments = ["--login", "-c", command]
|
task.arguments = ["--login", "-c", command]
|
||||||
|
|
||||||
let pipe = Pipe()
|
let pipe = Pipe()
|
||||||
@ -51,13 +51,7 @@ class Shell {
|
|||||||
|
|
||||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||||
|
|
||||||
let output: String = NSString(
|
let output: String = NSString(data: data, encoding: String.Encoding.utf8.rawValue)! as String
|
||||||
data: data,
|
|
||||||
encoding: String.Encoding.utf8.rawValue
|
|
||||||
)!.replacingOccurrences(
|
|
||||||
of: "\u{1B}(B\u{1B}[m",
|
|
||||||
with: ""
|
|
||||||
) as String
|
|
||||||
|
|
||||||
let historyItem = ShellHistoryItem(command: command, output: output)
|
let historyItem = ShellHistoryItem(command: command, output: output)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user