Skip to content

Commit 0fc7f2c

Browse files
📝 Minor tweaks, updated README
1 parent eebfa82 commit 0fc7f2c

File tree

10 files changed

+38
-21
lines changed

10 files changed

+38
-21
lines changed

README.md

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
# phpmon
22

3-
<img src="./docs/phpmon.png" width="306px" alt="phpmon screenshot"/>
3+
phpmon is a macOS utility that runs on your Mac and displays the active PHP version in your status bar.
44

5-
This version of phpmon was developed on and is for **macOS Mojave** with a working Homebrew installation and Laravel Valet 2.2.
5+
<img src="./docs/screenshot.png" width="278px" alt="phpmon screenshot"/>
66

7-
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.
7+
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.
8+
9+
This version of phpmon was developed for:
10+
11+
* macOS Mojave (10.14)
12+
* 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))
13+
* Laravel Valet 2.2
14+
15+
## Why I built this
16+
17+
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.
18+
19+
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).
820

921
## How it works
1022

1123
### Version detection
1224

13-
This utility runs `php -r 'print phpversion();'` in the background periodically and extracts the version number.
25+
This utility runs `php -r 'print phpversion();'` in the background periodically (every 60 seconds) and extracts the version number.
1426

1527
### Switching PHP versions
1628

@@ -29,4 +41,8 @@ The utility runs the following commands:
2941
- Tell Valet to switch to a specific PHP version
3042
- Link the desired version of PHP
3143

32-
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.
44+
### Want to know more?
45+
46+
If you want to know more about how this works, I recommend you check out the source code.
47+
48+
This app isn't very complicated after all. In the end, this just (conveniently) executes some shell commands.

docs/phpmon.png

-317 KB
Binary file not shown.

docs/screenshot.png

314 KB
Loading

phpmon/AppDelegate.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
1919
// MARK: - Initializer
2020

2121
override init() {
22-
self.sharedShell = Shell.shared
22+
self.sharedShell = Shell.user
2323
self.state = App.shared
2424
self.menu = MainMenu.shared
2525
super.init()

phpmon/Classes/Commands/Actions.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import AppKit
1212
class Actions {
1313

1414
public static func detectPhpVersions() -> [String] {
15-
let files = Shell.shared.pipe("ls /usr/local/opt | grep php@")
15+
let files = Shell.user.pipe("ls /usr/local/opt | grep php@")
1616
var versions = files.components(separatedBy: "\n")
1717
// Remove all empty strings
1818
versions.removeAll { (string) -> Bool in
@@ -28,14 +28,14 @@ class Actions {
2828

2929
public static func switchToPhpVersion(version: String, availableVersions: [String]) {
3030
availableVersions.forEach { (version) in
31-
Shell.shared.run("brew unlink php@\(version)")
31+
Shell.user.run("brew unlink php@\(version)")
3232
}
3333
if (availableVersions.contains("7.3")) {
34-
Shell.shared.run("brew link [email protected]")
34+
Shell.user.run("brew link [email protected]")
3535
if (version == Constants.LatestPhpVersion) {
36-
Shell.shared.run( "valet use php")
36+
Shell.user.run( "valet use php")
3737
} else {
38-
Shell.shared.run("valet use php@\(version)")
38+
Shell.user.run("valet use php@\(version)")
3939
}
4040
}
4141
}

phpmon/Classes/Commands/Startup.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@ class Startup {
1313
public static func checkEnvironment()
1414
{
1515
self.presentAlertOnMainThreadIf(
16-
!Shell.shared.pipe("which php").contains("/usr/local/bin/php"),
16+
!Shell.user.pipe("which php").contains("/usr/local/bin/php"),
1717
messageText: "PHP is not correctly installed",
1818
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."
1919
)
2020

2121
self.presentAlertOnMainThreadIf(
22-
!Shell.shared.pipe("ls /usr/local/opt | grep [email protected]").contains("[email protected]"),
22+
!Shell.user.pipe("ls /usr/local/opt | grep [email protected]").contains("[email protected]"),
2323
messageText: "PHP 7.3 is not correctly installed",
2424
informativeText: "PHP 7.3 alias was not found in `/usr/local/opt`. The app will not work correctly until you resolve this issue."
2525
)
2626

2727
self.presentAlertOnMainThreadIf(
28-
!Shell.shared.pipe("which valet").contains("/usr/local/bin/valet"),
28+
!Shell.user.pipe("which valet").contains("/usr/local/bin/valet"),
2929
messageText: "Laravel Valet is not correctly installed",
3030
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."
3131
)
3232

3333
self.presentAlertOnMainThreadIf(
34-
!Shell.shared.pipe("cat /private/etc/sudoers.d/brew").contains("/usr/local/bin/brew"),
34+
!Shell.user.pipe("cat /private/etc/sudoers.d/brew").contains("/usr/local/bin/brew"),
3535
messageText: "Brew has not been added to sudoers.d",
3636
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."
3737
)
3838

3939
self.presentAlertOnMainThreadIf(
40-
!Shell.shared.pipe("cat /private/etc/sudoers.d/valet").contains("/usr/local/bin/valet"),
40+
!Shell.user.pipe("cat /private/etc/sudoers.d/valet").contains("/usr/local/bin/valet"),
4141
messageText: "Valet has not been added to sudoers.d",
4242
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."
4343
)

phpmon/Classes/Helpers/PhpVersion.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class PhpVersion {
1414
var long : String = "???"
1515

1616
init() {
17-
let version = Shell.shared
17+
let version = Shell.user
1818
// Get the version directly from PHP
1919
.pipe("php -r 'print phpversion();'")
2020

phpmon/Singletons/MainMenu.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,6 @@ class MainMenu: NSObject, NSWindowDelegate {
149149

150150
func windowWillClose(_ notification: Notification) {
151151
App.shared.windowController = nil
152-
Shell.shared.delegate = nil
152+
Shell.user.delegate = nil
153153
}
154154
}

phpmon/Singletons/Shell.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class ShellHistoryItem {
2626

2727
class Shell {
2828

29-
static let shared = Shell()
29+
// Singleton to access a user shell (with --login)
30+
static let user = Shell()
3031

3132
var history : [ShellHistoryItem] = []
3233

phpmon/View Controllers/LogViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class LogViewController: NSViewController, ShellDelegate {
1313
public static func show(delegate: NSWindowDelegate? = nil) {
1414
if (App.shared.windowController == nil) {
1515
let vc = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "logWindow") as! LogViewController
16-
Shell.shared.delegate = vc
16+
Shell.user.delegate = vc
1717
let window = NSWindow(contentViewController: vc)
1818
window.title = "Terminal Output"
1919
window.delegate = delegate
@@ -53,7 +53,7 @@ class LogViewController: NSViewController, ShellDelegate {
5353

5454
override func viewDidLoad() {
5555
self.textView.isEditable = false
56-
for entry in Shell.shared.history {
56+
for entry in Shell.user.history {
5757
self.appendHistoryItem(entry)
5858
}
5959
}

0 commit comments

Comments
 (0)