Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Say Installed for the peel command once its link leads to this copy

Țugui Dragoș0cb0199e31f8
diff --git a/Packages/PeelCore/Sources/PeelCore/Home/Access.swift b/Packages/PeelCore/Sources/PeelCore/Home/Access.swift
index c959a07a..da35379c 100644
--- a/Packages/PeelCore/Sources/PeelCore/Home/Access.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Home/Access.swift
@@ -83,16 +83,16 @@ public enum CommandLineTool {
return applications.contains { PathComponents.isPath(path, inside: $0) } ? .applications : .elsewhere
}
- /// The shell command that links the tool, built from where Peel really is rather than a fixed path, or nil
- /// where something that may not be Peel's is in the link's place. `ln -f` deletes what is there, so only a link
- /// to another Peel's tool is replaced. A single quote in the path is closed, escaped, and reopened, so the shell
- /// reads the path as written.
+ /// The shell command that links the tool, built from where Peel really is rather than a fixed path, or nil once the
+ /// link leads to this copy's tool and where something that may not be Peel's is in the link's place. `ln -f`
+ /// deletes what is there, so only a link to another Peel's tool is replaced. A single quote in the path is closed,
+ /// escaped, and reopened, so the shell reads the path as written.
public static func installCommand(embedded: URL, standing: Standing) -> String? {
let path = embedded.path(percentEncoded: false).replacingOccurrences(of: "'", with: "'\\''")
let link = switch standing {
- case .installed, .missing: "ln -s"
+ case .missing: "ln -s"
case .otherPeel: "ln -sf"
- case .somethingElse: nil as String?
+ case .installed, .somethingElse: nil as String?
}
return link.map { "sudo mkdir -p /usr/local/bin && sudo \($0) '\(path)' \(CommandLineTool.path)" }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift
index 7531231e..86e9950e 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomeTests.swift
@@ -244,13 +244,15 @@ struct AppManagementTests {
}
/// `ln -f` deletes what is in the link's place, for good, so it replaces only a link to another Peel's tool,
- /// and Peel offers no command at all where something else is.
+ /// and Peel offers no command at all where something else is, nor once the link leads to this copy, where `ln -s`
+ /// would fail.
@Test func neverOffersACommandThatReplacesWhatIsNotPeels() throws {
let embedded = URL(filePath: "/Applications/Peel.app/Contents/Helpers/peel")
#expect(CommandLineTool.installCommand(embedded: embedded, standing: .missing) == "sudo mkdir -p /usr/local/bin && sudo ln -s '/Applications/Peel.app/Contents/Helpers/peel' /usr/local/bin/peel")
#expect(CommandLineTool.installCommand(embedded: embedded, standing: .otherPeel) == "sudo mkdir -p /usr/local/bin && sudo ln -sf '/Applications/Peel.app/Contents/Helpers/peel' /usr/local/bin/peel")
#expect(CommandLineTool.installCommand(embedded: embedded, standing: .somethingElse) == nil)
+ #expect(CommandLineTool.installCommand(embedded: embedded, standing: .installed) == nil)
}
/// Installed with Homebrew on a Mac with Apple silicon, the `peel` command is Homebrew's link in
diff --git a/Peel/Views/Home/HomePermissionsView.swift b/Peel/Views/Home/HomePermissionsView.swift
index 87bbc110..a42dc3a5 100644
--- a/Peel/Views/Home/HomePermissionsView.swift
+++ b/Peel/Views/Home/HomePermissionsView.swift
@@ -166,7 +166,7 @@ struct HomePermissionsContent: View {
private func action(_ permission: HomeModel.Permission, state: HomeModel.State) -> some View {
if let action = home.action(for: permission) {
// The command-line row uses `CopyButton`, which says "Copied" once the command is on the pasteboard.
- if permission == .commandLine, let command = SettingsKey.commandLineInstallCommand {
+ if permission == .commandLine, let command = SettingsKey.commandLineInstallCommand() {
CopyButton(text: command, title: action)
.buttonStyle(.stickerQuiet)
.accessibilityLabel(Text("\(String(localized: action)): \(String(localized: permission.title))", comment: "What VoiceOver reads for a button. The first %@ is the action, such as Install. The second is what it acts on, such as Helper."))
@@ -345,7 +345,7 @@ fileprivate extension HomeModel {
case .finderExtension, .openAtLogin: return nil
// Short on purpose: every row shares the grid's button column, so a wide label here would narrow
// every row's name. The row's name says what is copied, and the note beside it explains.
- case .commandLine: return state == .on || SettingsKey.commandLineInstallCommand == nil ? nil : "Copy"
+ case .commandLine: return state == .on || SettingsKey.commandLineInstallCommand() == nil ? nil : "Copy"
}
}
}
diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swift
index d1a6ed01..59253502 100644
--- a/Peel/Views/Settings/SettingsView.swift
+++ b/Peel/Views/Settings/SettingsView.swift
@@ -133,11 +133,13 @@ enum SettingsKey {
static let skippedUpdateVersions = UpdatePreferences.Key.skippedVersions
static let updateMemory = "updateMemory"
- /// Nil while something that may not be Peel's is where the link goes.
- static var commandLineInstallCommand: String? {
+ /// Nil once the link leads to this copy's tool, and while something that may not be Peel's is where it goes.
+ static func commandLineInstallCommand(
+ for standing: CommandLineTool.Standing = HomeModel.commandLineStanding
+ ) -> String? {
CommandLineTool.installCommand(
embedded: Bundle.main.bundleURL.appending(path: "Contents/Helpers/peel"),
- standing: HomeModel.commandLineStanding
+ standing: standing
)
}
}
@@ -178,7 +180,8 @@ private func state(_ title: LocalizedStringResource, _ symbol: String, _ tint: C
}
private struct GeneralSettingsView: View {
- private var installCommand: String? { SettingsKey.commandLineInstallCommand }
+ @State private var commandLine = HomeModel.commandLineStanding
+ private var installCommand: String? { SettingsKey.commandLineInstallCommand(for: commandLine) }
private static let place = CommandLineTool.place()
@AppStorage(SettingsKey.checksForAppUpdates) private var checksForAppUpdates = true
@@ -225,6 +228,7 @@ private struct GeneralSettingsView: View {
}
private func readStandings() {
+ commandLine = HomeModel.commandLineStanding
let status = SMAppService.mainApp.status
opensAtLogin = status == .enabled || status == .requiresApproval
needsApprovalToOpenAtLogin = status == .requiresApproval
@@ -347,8 +351,10 @@ private struct GeneralSettingsView: View {
}
}
LabeledContent {
- // Not offered from a temporary copy: a link into it would break as soon as Peel quits.
- if Self.place != .temporaryCopy, let installCommand {
+ if commandLine == .installed {
+ state("Installed", "checkmark.circle", .green)
+ } else if Self.place != .temporaryCopy, let installCommand {
+ // Not offered from a temporary copy: a link into it would break as soon as Peel quits.
CopyButton(text: installCommand)
}
} label: {
@@ -367,7 +373,7 @@ private struct GeneralSettingsView: View {
.font(.caption)
.foregroundStyle(.secondary)
}
- if Self.place != .temporaryCopy {
+ if Self.place != .temporaryCopy, commandLine != .installed {
if let installCommand {
Text(verbatim: installCommand)
.font(.caption.monospaced())