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.

Clean Up names the formulae Homebrew would uninstall

Țugui Dragoșd0da6a1dd6b5
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 4486bfaf..8eb9f658 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -48371,6 +48371,352 @@
}
}
},
+ "It uninstalls ^[%lld formula](inflect: true) that nothing needs anymore: %@." : {
+ "localizations" : {
+ "cs" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstaluje %lld formulae, které už nic nepotřebuje: %@."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstaluje %lld formulae, které už nic nepotřebuje: %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstaluje %lld formula, kterou už nic nepotřebuje: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstaluje %lld formulae, které už nic nepotřebuje: %@."
+ }
+ }
+ }
+ }
+ },
+ "de" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew deinstalliert %lld Formula, die von nichts mehr benötigt wird: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew deinstalliert %lld Formulae, die von nichts mehr benötigt werden: %@."
+ }
+ }
+ }
+ }
+ },
+ "en" : {
+ "stringUnit" : {
+ "state" : "new",
+ "value" : "It uninstalls ^[%1$lld formula](inflect: true) that nothing needs anymore: %2$@."
+ }
+ },
+ "es" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Desinstala %lld de formulae de las que ya no depende nada: %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Desinstala %lld formula de la que ya no depende nada: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Desinstala %lld formulae de las que ya no depende nada: %@."
+ }
+ }
+ }
+ }
+ },
+ "fr" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il désinstalle %lld de formulae dont plus rien n’a besoin : %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il désinstalle %lld formula dont plus rien n’a besoin : %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Il désinstalle %lld formulae dont plus rien n’a besoin : %@."
+ }
+ }
+ }
+ }
+ },
+ "it" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Disinstalla %lld di formulae che non servono più a nulla: %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Disinstalla %lld formula che non serve più a nulla: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Disinstalla %lld formulae che non servono più a nulla: %@."
+ }
+ }
+ }
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "もう何にも必要とされていない%lld個のformulaeをアンインストールします: %@。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew는 더 이상 필요하지 않은 formula %lld개를 제거합니다: %@."
+ }
+ },
+ "nl" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het deïnstalleert %lld formula waar niets meer van afhankelijk is: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Het deïnstalleert %lld formulae waar niets meer van afhankelijk is: %@."
+ }
+ }
+ }
+ }
+ },
+ "pl" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstalowuje %lld formulae, których nic już nie potrzebuje: %@."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstalowuje %lld formulae, których nic już nie potrzebuje: %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstalowuje %lld formula, której nic już nie potrzebuje: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Odinstalowuje %lld formulae, których nic już nie potrzebuje: %@."
+ }
+ }
+ }
+ }
+ },
+ "pt" : {
+ "variations" : {
+ "plural" : {
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ele desinstala %lld de formulae de que nada mais precisa: %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ele desinstala %lld formula de que nada mais precisa: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Ele desinstala %lld formulae de que nada mais precisa: %@."
+ }
+ }
+ }
+ }
+ },
+ "ro" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dezinstalează %lld formule de care nu mai are nevoie nimic: %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dezinstalează %lld formulă de care nu mai are nevoie nimic: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Dezinstalează %lld de formule de care nu mai are nevoie nimic: %@."
+ }
+ }
+ }
+ }
+ },
+ "ru" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew удаляет %lld formulae, которые больше ничему не нужны: %@."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew удаляет %lld formulae, которые больше ничему не нужны: %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew удаляет %lld formula, которая больше ничему не нужна: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew удаляет %lld formulae, которые больше ничему не нужны: %@."
+ }
+ }
+ }
+ }
+ },
+ "sv" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew avinstallerar %lld formula som inget längre behöver: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew avinstallerar %lld formulae som inget längre behöver: %@."
+ }
+ }
+ }
+ }
+ },
+ "tr" : {
+ "variations" : {
+ "plural" : {
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Artık hiçbir şeyin ihtiyaç duymadığı %lld formula da kaldırılır: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Artık hiçbir şeyin ihtiyaç duymadığı %lld formula da kaldırılır: %@."
+ }
+ }
+ }
+ }
+ },
+ "uk" : {
+ "variations" : {
+ "plural" : {
+ "few" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Він деінсталює %lld formulae, які більше нічому не потрібні: %@."
+ }
+ },
+ "many" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Він деінсталює %lld formulae, які більше нічому не потрібні: %@."
+ }
+ },
+ "one" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Він деінсталює %lld formula, яка більше нічому не потрібна: %@."
+ }
+ },
+ "other" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Він деінсталює %lld formulae, які більше нічому не потрібні: %@."
+ }
+ }
+ }
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它会卸载%lld个不再被需要的formula:%@。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "它會解除安裝%lld個不再被需要的formulae:%@。"
+ }
+ }
+ }
+ },
"It was first seen signed by %@, and is signed by %@ now." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
index 21292e2b..bd9139f1 100644
--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
@@ -464,15 +464,33 @@ public enum Homebrew {
return (try? JSONDecoder().decode(HomebrewTrust.self, from: Data(output.utf8))) ?? HomebrewTrust()
}
- /// What `brew cleanup` would free. Nothing is removed: `--dry-run` only reports.
+ /// What `brew cleanup` would do, as its dry run says.
+ public struct CleanupPreview: Sendable, Hashable {
+ /// What it would free, leaving out the formulae it would autoremove. Nil when Homebrew's words can't be read.
+ public let bytes: Int64?
+ /// The formulae it would uninstall for good because nothing needs them anymore.
+ public let autoremoved: [String]
+ }
+
+ /// What `brew cleanup` would do. Nothing is removed: `--dry-run` only reports.
@concurrent
- public static func reclaimableBytes(
+ public static func cleanupPreview(
asWrittenBy installation: HomebrewInstallation?, keeping kept: [String]
- ) async -> Int64? {
+ ) async -> CleanupPreview? {
guard let output = try? await execute(
["cleanup", "--dry-run"], autoUpdate: false, keeping: kept, timeout: longestAnswer
).answer() else { return nil }
- return reclaimableBytes(in: output, countsInThousands: installation?.countsInThousands ?? true)
+ return CleanupPreview(
+ bytes: reclaimableBytes(in: output, countsInThousands: installation?.countsInThousands ?? true),
+ autoremoved: autoremovedFormulae(in: output)
+ )
+ }
+
+ /// Reads the formulae named under the "Would autoremove" headline, one to a line.
+ static func autoremovedFormulae(in output: String) -> [String] {
+ let lines = output.split(whereSeparator: \.isNewline).map(String.init)
+ guard let headline = lines.firstIndex(where: { $0.hasPrefix("==> Would autoremove") }) else { return [] }
+ return Array(lines[(headline + 1)...].prefix { !$0.isEmpty && !$0.contains(" ") })
}
/// Reads the total from the one sentence where Homebrew gives it, such as "would free approximately
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
index 475a9a0c..9319bd74 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/HomebrewTests.swift
@@ -345,6 +345,23 @@ struct HomebrewTests {
#expect(Homebrew.reclaimableBytes(in: output, countsInThousands: true) == 61_200_000)
}
+ /// `brew cleanup` autoremoves too (Homebrew 7.0.4's `cleanup.rb`), and its dry run names each formula it would
+ /// uninstall under one headline, which Clean Up's confirmation repeats.
+ @Test func readsWhichFormulaeACleanUpWouldAutoremove() {
+ let output = """
+ Would remove: /opt/homebrew/Cellar/x265/4.2 (12 files, 17MB)
+ ==> Would autoremove 2 unneeded formulae:
+ libfoo
+ org/tap/bar
+ Would remove: /Users/me/Library/Caches/Homebrew/downloads/abc--x265-4.2.bottle.tar.gz (2MB)
+ ==> This operation would free approximately 61.2MB of disk space.
+ """
+
+ #expect(Homebrew.autoremovedFormulae(in: output) == ["libfoo", "org/tap/bar"])
+ let nothingToAutoremove = "==> This operation would free approximately 3KB of disk space."
+ #expect(Homebrew.autoremovedFormulae(in: nothingToAutoremove).isEmpty)
+ }
+
/// Homebrew drops the decimal on a round number, and its largest unit is GB. From 5.0.0 it counts in thousands
/// (`utils/formatter.rb` divides by 1000.0). Earlier versions count in 1024s, whatever the unit says.
@Test func readsEveryUnitACleanUpUses() {
diff --git a/Peel/Model/HomebrewLibrary.swift b/Peel/Model/HomebrewLibrary.swift
index 1655f368..7a0a75b3 100644
--- a/Peel/Model/HomebrewLibrary.swift
+++ b/Peel/Model/HomebrewLibrary.swift
@@ -49,6 +49,8 @@ final class HomebrewLibrary {
private(set) var installation: HomebrewInstallation?
/// What `brew cleanup` would free, as Homebrew reported it. Nil when it wouldn't say.
private(set) var reclaimable: Int64?
+ /// The formulae `brew cleanup` would uninstall for good because nothing needs them anymore.
+ private(set) var autoremovable: [String] = []
/// What Homebrew's own settings undo of how Peel runs it, read with the page and before an upgrade.
private(set) var overrides: Homebrew.Overrides = []
/// Homebrew has no local copy of its package definitions, for example because its cache was cleared (not
@@ -128,7 +130,7 @@ final class HomebrewLibrary {
isInstalled = Homebrew.executableURL != nil
guard isInstalled else { return }
guard let reading = await scanRun.run({ await self.read(includingReclaimable: includingReclaimable) }) else { return }
- guard let (found, installed, bytes, overridden) = reading else {
+ guard let (found, installed, preview, overridden) = reading else {
needsDefinitions = true
packages = packages ?? []
return
@@ -145,7 +147,10 @@ final class HomebrewLibrary {
}
self.installation = found
// Keeps the last figure when this reading brought none: one that was right a moment ago beats none.
- self.reclaimable = bytes ?? self.reclaimable
+ if let preview {
+ reclaimable = preview.bytes ?? reclaimable
+ autoremovable = preview.autoremoved
+ }
overrides = overridden ?? overrides
revision += 1
if let selection, packages?.contains(where: { $0.id == selection }) != true {
@@ -156,15 +161,17 @@ final class HomebrewLibrary {
/// Nil while Homebrew has no local definitions to read, as when `brew update` has never run.
private func read(
includingReclaimable: Bool
- ) async -> (HomebrewInstallation?, Result<[HomebrewPackage], Homebrew.CommandFailure>, Int64?, Homebrew.Overrides?)? {
+ ) async -> (
+ HomebrewInstallation?, Result<[HomebrewPackage], Homebrew.CommandFailure>, Homebrew.CleanupPreview?,
+ Homebrew.Overrides?
+ )? {
guard await Homebrew.hasLocalDefinitions() else { return nil }
needsDefinitions = false
// The installation is read first, since it says how to read the figures that follow. The other questions
// take about as long as each other, so they run at the same time. Only the page shows the last two.
let found = await Homebrew.installation()
let kept = found.map { ExclusionsStore.shared.exclusions.keptFormulae(inCellarOf: $0.prefix) } ?? []
- async let reclaimable = includingReclaimable
- ? Homebrew.reclaimableBytes(asWrittenBy: found, keeping: kept) : nil
+ async let preview = includingReclaimable ? Homebrew.cleanupPreview(asWrittenBy: found, keeping: kept) : nil
async let overridden = includingReclaimable ? Homebrew.overrides() : nil
let installed: Result<[HomebrewPackage], Homebrew.CommandFailure>
do {
@@ -172,7 +179,7 @@ final class HomebrewLibrary {
} catch {
installed = .failure(error)
}
- return (found, installed, await reclaimable, await overridden)
+ return (found, installed, await preview, await overridden)
}
/// Runs `command` and returns its result to the caller. Only one command runs at a time: while one runs,
diff --git a/Peel/Views/Homebrew/HomebrewList.swift b/Peel/Views/Homebrew/HomebrewList.swift
index 88fd7a1d..2c4c4e7c 100644
--- a/Peel/Views/Homebrew/HomebrewList.swift
+++ b/Peel/Views/Homebrew/HomebrewList.swift
@@ -68,11 +68,7 @@ struct HomebrewList: View {
Button("Clean Up", role: .destructive) { start(.cleanup) }
Button("Cancel", role: .cancel) {}
} message: {
- if let reclaimable = homebrew.reclaimable, reclaimable > 0 {
- Text("Homebrew deletes these for good: about \(reclaimable.byteCount) of downloads and old versions, and any formulae that were only there for something now gone, which that figure leaves out. Nothing goes to the Trash, and History can’t put it back.")
- } else {
- Text("Homebrew deletes these for good: the downloads and old versions it kept, and any formulae that were only there for something now gone. Nothing goes to the Trash, and History can’t put it back.")
- }
+ Text(verbatim: cleanUpWarning)
}
.task {
// Only this page shows what Clean Up would free, so the figure is asked for here, and only while
@@ -82,6 +78,21 @@ struct HomebrewList: View {
}
}
+ /// What Clean Up deletes for good, with the formulae it would uninstall named, since those are packages.
+ private var cleanUpWarning: String {
+ var sentences: [String] = []
+ if let reclaimable = homebrew.reclaimable, reclaimable > 0 {
+ sentences.append(String(localized: "Homebrew deletes these for good: about \(reclaimable.byteCount) of downloads and old versions, and any formulae that were only there for something now gone, which that figure leaves out. Nothing goes to the Trash, and History can’t put it back."))
+ } else {
+ sentences.append(String(localized: "Homebrew deletes these for good: the downloads and old versions it kept, and any formulae that were only there for something now gone. Nothing goes to the Trash, and History can’t put it back."))
+ }
+ let formulae = homebrew.autoremovable
+ if !formulae.isEmpty {
+ sentences.append(String(inflecting: "It uninstalls ^[\(formulae.count) formula](inflect: true) that nothing needs anymore: \(formulae.formatted(.list(type: .and)))."))
+ }
+ return sentences.joined(separator: "\n\n")
+ }
+
// MARK: - Homebrew itself
/// What Homebrew's own settings undo of how Peel runs it, said before anything is run.