diff --git a/README.md b/README.md index 56421e1..bdb7693 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,28 @@ # phpmon -phpmon screenshot +phpmon is a macOS utility that runs on your Mac and displays the active PHP version in your status bar. -This version of phpmon was developed on and is for **macOS Mojave** with a working Homebrew installation and Laravel Valet 2.2. +phpmon screenshot -phpmon is a macOS utility that runs on your Mac and displays the active PHP version in your status bar. Handy if you're running multiple versions of PHP with Homebrew and wish to see which version is currently linked & active with Laravel Valet. +For me, it comes in handy when running multiple versions of PHP with Homebrew and you wish to be able to see at a glance which version is currently linked & active with Laravel Valet, and switch between versions. + +This version of phpmon was developed for: + +* macOS Mojave (10.14) +* PHP 7.x with Homebrew 2.x (with support for PHP 5.6 and PHP 7.0 [as well](https://github.com/eXolnet/homebrew-deprecated)) +* Laravel Valet 2.2 + +## Why I built this + +I wanted to be able to see at a glance which version of PHP was linked, and handle dealing with Laravel Valet in a simple app without having to deal with the terminal every time. + +Initially, I had an Alfred workflow for this. But this does the job as well, while also showing me at all times which version of PHP is linked (which is the main benefit over e.g. an Alfred workflow). ## How it works ### Version detection -This utility runs `php -r 'print phpversion();'` in the background periodically and extracts the version number. +This utility runs `php -r 'print phpversion();'` in the background periodically (every 60 seconds) and extracts the version number. ### Switching PHP versions @@ -29,4 +41,8 @@ The utility runs the following commands: - Tell Valet to switch to a specific PHP version - Link the desired version of PHP -If you want to know more about how this works, I recommend you check out the source code. This app isn't very complicated after all. In the end, this just (conveniently) executes some shell commands. +### Want to know more? + +If you want to know more about how this works, I recommend you check out the source code. + +This app isn't very complicated after all. In the end, this just (conveniently) executes some shell commands. diff --git a/docs/phpmon.png b/docs/phpmon.png deleted file mode 100644 index 7f0c713..0000000 Binary files a/docs/phpmon.png and /dev/null differ diff --git a/docs/screenshot.png b/docs/screenshot.png new file mode 100644 index 0000000..a7cd726 Binary files /dev/null and b/docs/screenshot.png differ diff --git a/phpmon/AppDelegate.swift b/phpmon/AppDelegate.swift index 9493999..7358364 100644 --- a/phpmon/AppDelegate.swift +++ b/phpmon/AppDelegate.swift @@ -19,7 +19,7 @@ class AppDelegate: NSObject, NSApplicationDelegate { // MARK: - Initializer override init() { - self.sharedShell = Shell.shared + self.sharedShell = Shell.user self.state = App.shared self.menu = MainMenu.shared super.init() diff --git a/phpmon/Classes/Commands/Actions.swift b/phpmon/Classes/Commands/Actions.swift index 07d2568..c979b39 100644 --- a/phpmon/Classes/Commands/Actions.swift +++ b/phpmon/Classes/Commands/Actions.swift @@ -12,7 +12,7 @@ import AppKit class Actions { public static func detectPhpVersions() -> [String] { - let files = Shell.shared.pipe("ls /usr/local/opt | grep php@") + let files = Shell.user.pipe("ls /usr/local/opt | grep php@") var versions = files.components(separatedBy: "\n") // Remove all empty strings versions.removeAll { (string) -> Bool in @@ -28,14 +28,14 @@ class Actions { public static func switchToPhpVersion(version: String, availableVersions: [String]) { availableVersions.forEach { (version) in - Shell.shared.run("brew unlink php@\(version)") + Shell.user.run("brew unlink php@\(version)") } if (availableVersions.contains("7.3")) { - Shell.shared.run("brew link php@7.3") + Shell.user.run("brew link php@7.3") if (version == Constants.LatestPhpVersion) { - Shell.shared.run( "valet use php") + Shell.user.run( "valet use php") } else { - Shell.shared.run("valet use php@\(version)") + Shell.user.run("valet use php@\(version)") } } } diff --git a/phpmon/Classes/Commands/Startup.swift b/phpmon/Classes/Commands/Startup.swift index 86d1b71..7bf6bd7 100644 --- a/phpmon/Classes/Commands/Startup.swift +++ b/phpmon/Classes/Commands/Startup.swift @@ -13,31 +13,31 @@ class Startup { public static func checkEnvironment() { self.presentAlertOnMainThreadIf( - !Shell.shared.pipe("which php").contains("/usr/local/bin/php"), + !Shell.user.pipe("which php").contains("/usr/local/bin/php"), messageText: "PHP is not correctly installed", informativeText: "You must install PHP via brew. Try running `which php` in Terminal, it should return `/usr/local/bin/php`. The app will not work correctly until you resolve this issue." ) self.presentAlertOnMainThreadIf( - !Shell.shared.pipe("ls /usr/local/opt | grep php@7.3").contains("php@7.3"), + !Shell.user.pipe("ls /usr/local/opt | grep php@7.3").contains("php@7.3"), messageText: "PHP 7.3 is not correctly installed", informativeText: "PHP 7.3 alias was not found in `/usr/local/opt`. The app will not work correctly until you resolve this issue." ) self.presentAlertOnMainThreadIf( - !Shell.shared.pipe("which valet").contains("/usr/local/bin/valet"), + !Shell.user.pipe("which valet").contains("/usr/local/bin/valet"), messageText: "Laravel Valet is not correctly installed", informativeText: "You must install Valet via brew. Try running `which valet` in Terminal, it should return `/usr/local/bin/valet`. The app will not work correctly until you resolve this issue." ) self.presentAlertOnMainThreadIf( - !Shell.shared.pipe("cat /private/etc/sudoers.d/brew").contains("/usr/local/bin/brew"), + !Shell.user.pipe("cat /private/etc/sudoers.d/brew").contains("/usr/local/bin/brew"), messageText: "Brew has not been added to sudoers.d", informativeText: "You must run `sudo valet trust` to ensure Valet can start and stop services without having to use sudo every time. The app will not work correctly until you resolve this issue." ) self.presentAlertOnMainThreadIf( - !Shell.shared.pipe("cat /private/etc/sudoers.d/valet").contains("/usr/local/bin/valet"), + !Shell.user.pipe("cat /private/etc/sudoers.d/valet").contains("/usr/local/bin/valet"), messageText: "Valet has not been added to sudoers.d", informativeText: "You must run `sudo valet trust` to ensure Valet can start and stop services without having to use sudo every time. The app will not work correctly until you resolve this issue." ) diff --git a/phpmon/Classes/Helpers/PhpVersion.swift b/phpmon/Classes/Helpers/PhpVersion.swift index 493c6dc..8d129ca 100644 --- a/phpmon/Classes/Helpers/PhpVersion.swift +++ b/phpmon/Classes/Helpers/PhpVersion.swift @@ -14,7 +14,7 @@ class PhpVersion { var long : String = "???" init() { - let version = Shell.shared + let version = Shell.user // Get the version directly from PHP .pipe("php -r 'print phpversion();'") diff --git a/phpmon/Singletons/MainMenu.swift b/phpmon/Singletons/MainMenu.swift index 5a7eac0..9af54f1 100644 --- a/phpmon/Singletons/MainMenu.swift +++ b/phpmon/Singletons/MainMenu.swift @@ -149,6 +149,6 @@ class MainMenu: NSObject, NSWindowDelegate { func windowWillClose(_ notification: Notification) { App.shared.windowController = nil - Shell.shared.delegate = nil + Shell.user.delegate = nil } } diff --git a/phpmon/Singletons/Shell.swift b/phpmon/Singletons/Shell.swift index 7fddc7d..1ff855d 100644 --- a/phpmon/Singletons/Shell.swift +++ b/phpmon/Singletons/Shell.swift @@ -26,7 +26,8 @@ class ShellHistoryItem { class Shell { - static let shared = Shell() + // Singleton to access a user shell (with --login) + static let user = Shell() var history : [ShellHistoryItem] = [] diff --git a/phpmon/View Controllers/LogViewController.swift b/phpmon/View Controllers/LogViewController.swift index f67a9ff..3df462c 100644 --- a/phpmon/View Controllers/LogViewController.swift +++ b/phpmon/View Controllers/LogViewController.swift @@ -13,7 +13,7 @@ class LogViewController: NSViewController, ShellDelegate { public static func show(delegate: NSWindowDelegate? = nil) { if (App.shared.windowController == nil) { let vc = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "logWindow") as! LogViewController - Shell.shared.delegate = vc + Shell.user.delegate = vc let window = NSWindow(contentViewController: vc) window.title = "Terminal Output" window.delegate = delegate @@ -53,7 +53,7 @@ class LogViewController: NSViewController, ShellDelegate { override func viewDidLoad() { self.textView.isEditable = false - for entry in Shell.shared.history { + for entry in Shell.user.history { self.appendHistoryItem(entry) } }