Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Keep the excluded formulae in the Homebrew commands Peel gives to copy
Țugui Dragoșfb2339a32c52
diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swiftindex 6bccecd1..873f7c36 100644--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift@@ -975,6 +975,15 @@ public enum Homebrew {return Set(kept).isSubset(of: keptFormulae(inConfig: config))}+ /// `command` for the person to run in Terminal, telling Homebrew to keep `kept`, the formulae the exclusions+ /// cover, as Peel's own runs do: an upgrade cleans up after itself and an uninstall removes what nothing needs,+ /// both for good. The list is quoted, since a folder in the Cellar can be called anything.+ public static func terminalCommand(_ command: String, keeping kept: [String]) -> String {+ guard !kept.isEmpty else { return command }+ let list = kept.joined(separator: ",").replacingOccurrences(of: "'", with: "'\\''")+ return "HOMEBREW_NO_CLEANUP_FORMULAE='\(list)' \(command)"+ }+/// Reads the `HOMEBREW_NO_CLEANUP_FORMULAE: a,b` line of `brew config`'s answer.static func keptFormulae(inConfig config: String) -> Set<String> {let prefix = "HOMEBREW_NO_CLEANUP_FORMULAE: "diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swiftindex 37f9717e..3bc8ad42 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift@@ -22,6 +22,14 @@ struct HomebrewTests {#expect(Homebrew.installation(versionAnswer: "Homebrew 7.0.9\n", prefixAnswer: "/p\n", cellarAnswer: "c\n") == nil)}+ @Test func aCommandForTerminalKeepsTheFormulaeTheExclusionsCover() {+ #expect(Homebrew.terminalCommand("brew upgrade --cask example", keeping: []) == "brew upgrade --cask example")+ #expect(+ Homebrew.terminalCommand("brew uninstall --cask example", keeping: ["openssl@3", "o'dd"])+ == "HOMEBREW_NO_CLEANUP_FORMULAE='openssl@3,o'\\''dd' brew uninstall --cask example"+ )+ }+@Test func asksForEachLineAsItGoesExceptOfTheHealthCheck() {#expect(Homebrew.environment(autoUpdate: false)["CI"] == "1")// `brew doctor` reads `CI` as a CI run and skips its check of the taps' branches (`diagnostic.rb`).diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swiftindex 5cac4b17..bff83c3c 100644--- a/Peel/Model/HomebrewLibrary.swift+++ b/Peel/Model/HomebrewLibrary.swift@@ -449,6 +449,12 @@ final class HomebrewLibrary {CommandResult(succeeded: false, output: String(localized: "Peel couldn’t make sure Homebrew keeps the formulae your exclusions cover, so it ran nothing. A brew.env file that sets HOMEBREW_NO_CLEANUP_FORMULAE replaces the list Peel gives it."))}+ /// The formulae the exclusions cover, read now, for a command the person runs in Terminal, or none when Peel+ /// can't tell which they are.+ var keptFormulaeNow: [String] {+ installation.flatMap { ExclusionsStore.shared.exclusions.keptFormulae(inCellar: $0.cellar) } ?? []+ }+/// The formulae Homebrew is told to keep, or what Peel says when it runs nothing.private enum Keeping {case formulae([String])diff --git a/Peel/Views/AppPageHeader.swift b/Peel/Views/AppPageHeader.swiftindex ac0d49f7..0ce29278 100644--- a/Peel/Views/AppPageHeader.swift+++ b/Peel/Views/AppPageHeader.swift@@ -165,7 +165,12 @@ struct AppPageHeader: View {.buttonStyle(.borderedProminent)case .homebrew where upgradeNeedsTerminal:if let cask = library.cask(for: plan.app) {- CopyButton(text: "brew upgrade --cask \(cask.fullName)", title: "Copy Upgrade Command")+ CopyButton(+ text: Homebrew.terminalCommand(+ "brew upgrade --cask \(cask.fullName)", keeping: homebrew.keptFormulaeNow+ ),+ title: "Copy Upgrade Command"+ )}case .homebrew:Button {diff --git a/Peel/Views/CopyButton.swift b/Peel/Views/CopyButton.swiftindex 19b20f98..87c137dd 100644--- a/Peel/Views/CopyButton.swift+++ b/Peel/Views/CopyButton.swift@@ -5,9 +5,15 @@ import SwiftUI/// A button that says it worked. Copying to the pasteboard changes nothing on screen, so without an answer/// the only way to know it took is to paste somewhere and look.struct CopyButton: View {- let text: String+ /// Read when the button is clicked, so it copies what holds then.+ let text: () -> Stringvar title: LocalizedStringResource = "Copy"+ init(text: @autoclosure @escaping () -> String, title: LocalizedStringResource = "Copy") {+ self.text = text+ self.title = title+ }+/// Counted, so a second click while "Copied" shows starts its time again.@State private var copies = 0@@ -17,7 +23,7 @@ struct CopyButton: View {Button {// The button exists to say the copy took, so it says so only when the pasteboard agrees.NSPasteboard.general.clearContents()- copies = NSPasteboard.general.setString(text, forType: .string) ? copies + 1 : 0+ copies = NSPasteboard.general.setString(text(), forType: .string) ? copies + 1 : 0// VoiceOver does not read a title that changes under its cursor, so the copy is announced as well.if hasCopied {AccessibilityNotification.Announcement(AttributedString(localized: "Copied")).post()diff --git a/Peel/Views/Homebrew/HomebrewDetailView.swift b/Peel/Views/Homebrew/HomebrewDetailView.swiftindex 4de23fd4..ebf14356 100644--- a/Peel/Views/Homebrew/HomebrewDetailView.swift+++ b/Peel/Views/Homebrew/HomebrewDetailView.swift@@ -135,7 +135,12 @@ struct HomebrewDetailView: View {} else if package.waitsForAnUpgrade {if package.upgradeNeedsAnAdministrator || homebrew.overrides.contains(.cleansUp) {let kind = package.kind == .cask ? "--cask" : "--formula"- CopyButton(text: "brew upgrade \(kind) \(package.fullName)", title: "Copy Upgrade Command")+ CopyButton(+ text: Homebrew.terminalCommand(+ "brew upgrade \(kind) \(package.fullName)", keeping: homebrew.keptFormulaeNow+ ),+ title: "Copy Upgrade Command"+ )} else {Button("Upgrade", systemImage: "arrow.down.circle") {isConfirmingUpgrade = true@@ -156,7 +161,12 @@ struct HomebrewDetailView: View {}Spacer()if isUninstalledInTerminal {- CopyButton(text: "brew uninstall --cask \(package.fullName)", title: "Copy Uninstall Command")+ CopyButton(+ text: Homebrew.terminalCommand(+ "brew uninstall --cask \(package.fullName)", keeping: homebrew.keptFormulaeNow+ ),+ title: "Copy Uninstall Command"+ )} else {Button("Uninstall", systemImage: "trash", role: .destructive) {isConfirmingUninstall = true