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.

Remove Peel gives Homebrew's command for a copy Homebrew installed

Țugui Dragoșa51fd1df97de
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 82986b6f..e124cd1c 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -36265,6 +36265,112 @@
}
}
},
+ "Homebrew installed this copy of Peel, so remove it with Homebrew, or Homebrew goes on listing it as installed. Run the command in Terminal: Homebrew deletes the app rather than moving it to the Trash, and moves Peel’s files to the Trash, its folder in Application Support among them. That folder holds History, your exclusions, and Saved Settings." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tuto kopii Peelu nainstaloval Homebrew, proto ji odstraňte pomocí Homebrew, jinak ji Homebrew bude dál uvádět jako nainstalovanou. Spusťte příkaz v Terminálu: Homebrew aplikaci smaže, místo aby ji přesunul do koše, a soubory Peelu přesune do koše, včetně jeho složky v Application Support. Tato složka obsahuje Historii, vaše výjimky a Uložená nastavení."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Da Homebrew diese Peel-Kopie installiert hat, entferne sie mit Homebrew, sonst führt Homebrew sie weiterhin als installiert. Führe den Befehl im Terminal aus: Homebrew löscht die App, statt sie in den Papierkorb zu legen, und legt die Dateien von Peel in den Papierkorb, darunter den Peel-Ordner in Application Support. Dieser Ordner enthält den Verlauf, deine Ausschlüsse und die gesicherten Einstellungen."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew instaló esta copia de Peel, así que elimínala con Homebrew, o Homebrew la seguirá mostrando como instalada. Ejecuta el comando en Terminal: Homebrew borra la app en vez de trasladarla a la papelera, y traslada a la papelera los archivos de Peel, incluida su carpeta de Application Support. Esa carpeta contiene Historial, tus exclusiones y Ajustes guardados."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew a installé cette copie de Peel : supprimez-la donc avec Homebrew, sinon Homebrew continuera de la considérer comme installée. Exécutez la commande dans Terminal : Homebrew supprime définitivement l’app au lieu de la placer dans la corbeille, et place dans la corbeille les fichiers de Peel, dont son dossier dans Application Support. Ce dossier contient l’Historique, vos exclusions et les Réglages enregistrés."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Questa copia di Peel è stata installata da Homebrew, quindi rimuovila con Homebrew, altrimenti Homebrew continuerà a elencarla come installata. Esegui il comando in Terminale: Homebrew elimina l’app anziché spostarla nel Cestino, e sposta nel Cestino i file di Peel, compresa la sua cartella in Application Support. Quella cartella contiene la Cronologia, le tue esclusioni e le Impostazioni salvate."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "このPeelはHomebrewでインストールされたため、Homebrewでアンインストールしてください。そうしないと、Homebrewでは引き続きインストール済みとして表示されます。ターミナルでコマンドを実行してください。Homebrewはアプリをゴミ箱に入れずに削除し、Peelのファイルは、Application SupportにあるPeelのフォルダも含めてゴミ箱に入れます。このフォルダには、履歴、除外リスト、“保存された設定”が含まれます。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew가 이 Peel 복사본을 설치했으므로 Homebrew로 제거하십시오. 그렇지 않으면 Homebrew는 이 복사본을 계속 설치된 것으로 표시합니다. 터미널에서 이 명령을 실행하십시오. 그러면 Homebrew가 앱을 휴지통으로 이동하지 않고 삭제하며, Application Support에 있는 Peel의 폴더를 포함한 Peel의 파일은 휴지통으로 이동합니다. 이 폴더에는 기록, 제외 항목, 저장된 설정이 들어 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew heeft deze kopie van Peel geïnstalleerd, dus verwijder die met Homebrew, anders blijft Homebrew die als geïnstalleerd vermelden. Voer het commando uit in Terminal: Homebrew verwijdert de app definitief in plaats van die naar de prullenmand te verplaatsen, en verplaatst de bestanden van Peel, waaronder de map in Application Support, naar de prullenmand. Die map bevat Geschiedenis, je uitsluitingen en 'Bewaarde instellingen'."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Tę kopię Peel zainstalował Homebrew, więc odinstaluj ją za pomocą Homebrew, w przeciwnym razie Homebrew nadal będzie ją wymieniał jako zainstalowaną. Uruchom polecenie w Terminalu: Homebrew usuwa aplikację trwale, zamiast przenosić ją do Kosza, a pliki Peel, w tym jego folder w Application Support, przenosi do Kosza. Ten folder zawiera Historię, Twoje wykluczenia i Zachowane ustawienia."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "O Homebrew instalou esta cópia do Peel, então remova-a com o Homebrew, senão o Homebrew vai continuar listando-a como instalada. Execute o comando no Terminal: o Homebrew apaga o app em vez de movê-lo para o Lixo, e move para o Lixo os arquivos do Peel, inclusive a pasta dele em Application Support. Essa pasta guarda o Histórico, as suas exclusões e os Ajustes Salvos."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew a instalat această copie Peel, așa că eliminați‑o cu Homebrew, altfel Homebrew o va lista în continuare ca instalată. Rulați comanda în Terminal: Homebrew șterge aplicația, în loc să o mute în Coș, și mută în Coș fișierele Peel, inclusiv dosarul său din Application Support. Acel dosar conține Istoricul, excluderile dvs. și Configurările salvate."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Эту копию Peel установил Homebrew, поэтому удалите ее с помощью Homebrew, иначе Homebrew будет по-прежнему считать ее установленной. Выполните команду в Терминале: Homebrew удаляет приложение безвозвратно, не перемещая его в Корзину, а файлы Peel, в том числе его папку в Application Support, перемещает в Корзину. В этой папке хранятся История, Ваши исключения и «Сохраненные настройки»."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Homebrew installerade den här kopian av Peel, så ta bort den med Homebrew, annars fortsätter Homebrew att lista den som installerad. Kör kommandot i Terminal: Homebrew raderar appen i stället för att flytta den till papperskorgen, men flyttar Peels filer, däribland dess mapp i Application Support, till papperskorgen. Den mappen innehåller Historik, dina undantag och Sparade inställningar."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Peel’in bu kopyasını Homebrew yükledi, bu yüzden onu Homebrew ile kaldırın, yoksa Homebrew onu yüklü olarak listelemeye devam eder. Komutu Terminal’de çalıştırın: Homebrew uygulamayı Çöp Sepeti’ne taşımak yerine siler, Peel’in dosyalarını ise, Application Support içindeki klasörü de dahil, Çöp Sepeti’ne taşır. O klasörde Geçmiş, hariç tutulanlar listeniz ve Kaydedilmiş Ayarlar bulunur."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Цю копію Peel інсталював Homebrew, тож вилучіть її через Homebrew, інакше він надалі показуватиме її у своєму списку інстальованого. Виконайте команду в Терміналі: Homebrew видалить саму програму, не переміщуючи її в Смітник, а файли Peel, зокрема її папку в Application Support, перемістить у Смітник. У цій папці зберігаються Історія, ваші винятки та «Збережені налаштування»."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "此Peel副本由Homebrew安装,因此请使用Homebrew移除它,否则Homebrew会继续将它列为已安装。请在“终端”中运行该命令:Homebrew会删除该App,而不是将它移到废纸篓,并会将Peel的文件移到废纸篓,其中包括它在Application Support中的文件夹。该文件夹中存有“历史记录”、你的排除项和“已保存的设置”。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "這份Peel副本是由Homebrew安裝的,因此請使用Homebrew移除它,否則Homebrew會繼續將它列為已安裝。請在「終端機」中執行此指令:Homebrew會刪除此App,而不是將它丟到「垃圾桶」,並會將Peel的檔案丟到「垃圾桶」,其中包括它在Application Support中的檔案夾。該檔案夾存有「歷史記錄」、你的排除項目和「已儲存的設定」。"
+ }
+ }
+ }
+ },
"Homebrew installs command-line tools as formulae and apps as casks. On this page Peel only runs Homebrew’s own commands and reads what they report." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
index 6ba43520..d94fd0e5 100644
--- a/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Homebrew/Homebrew.swift
@@ -24,6 +24,9 @@ public struct HomebrewPackage: Sendable, Hashable, Identifiable {
public let appNames: [String]
/// Where Homebrew put them, for a cask that is installed: "/Applications/Pearcleaner.app".
public let appTargets: [String]
+ /// Where Homebrew linked the commands an installed cask puts on the path: "/opt/homebrew/bin/pearcleaner".
+ /// `brew uninstall` removes these links.
+ public let commandLinks: [String]
/// Bundle identifiers the cask tells macOS to quit, which prove a cask really is a given app.
public let quitIdentifiers: [String]
/// Installer receipts the cask forgets, which can prove the cask for an app installed from a `.pkg`.
@@ -63,6 +66,7 @@ public struct HomebrewPackage: Sendable, Hashable, Identifiable {
dependencies: [String] = [],
appNames: [String] = [],
appTargets: [String] = [],
+ commandLinks: [String] = [],
leftoverPatterns: [String] = [],
emptyFolderPatterns: [String] = [],
quitIdentifiers: [String] = [],
@@ -82,6 +86,7 @@ public struct HomebrewPackage: Sendable, Hashable, Identifiable {
self.dependencies = dependencies
self.appNames = appNames
self.appTargets = appTargets
+ self.commandLinks = commandLinks
self.leftoverPatterns = leftoverPatterns
self.emptyFolderPatterns = emptyFolderPatterns
self.quitIdentifiers = quitIdentifiers
@@ -201,6 +206,7 @@ public struct HomebrewVulnerabilityReport: Sendable, Hashable {
struct CaskArtifact: Decodable, Sendable {
let appNames: [String]
let appTargets: [String]
+ let commandLinks: [String]
let leftoverPatterns: [String]
let emptyFolderPatterns: [String]
/// Bundle identifiers the cask tells macOS to quit. The surest sign a cask really is a given app.
@@ -220,6 +226,8 @@ struct CaskArtifact: Decodable, Sendable {
.filter { !$0.isEmpty }
// An installed cask also says where the app went: `{"app": [...], "target": "/Applications/Krita.app"}`.
appTargets = app == nil ? [] : (raw["target"]?.strings ?? []).filter { $0.hasPrefix("/") }
+ // A command's link is written the same way: `{"binary": [...], "target": "/opt/homebrew/bin/studio"}`.
+ commandLinks = raw["binary"] == nil ? [] : (raw["target"]?.strings ?? []).filter { $0.hasPrefix("/") }
var patterns: [String] = []
var emptyFolders: [String] = []
@@ -520,6 +528,7 @@ public enum Homebrew {
dependencies: [],
appNames: cask.artifacts?.flatMap(\.appNames) ?? [],
appTargets: cask.artifacts?.flatMap(\.appTargets) ?? [],
+ commandLinks: cask.artifacts?.flatMap(\.commandLinks) ?? [],
leftoverPatterns: cask.artifacts?.flatMap(\.leftoverPatterns) ?? [],
emptyFolderPatterns: cask.artifacts?.flatMap(\.emptyFolderPatterns) ?? [],
quitIdentifiers: cask.artifacts?.flatMap(\.quitIdentifiers) ?? [],
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CaskEvidenceTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CaskEvidenceTests.swift
index 22f3123b..811d62a1 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CaskEvidenceTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CaskEvidenceTests.swift
@@ -48,6 +48,18 @@ struct CaskEvidenceTests {
return packages
}
+ /// An installed cask says where Homebrew linked each command it put on the path, which are the links
+ /// `brew uninstall` removes. A cask that is not installed has linked nothing.
+ @Test func readsWhereHomebrewLinkedACasksCommands() throws {
+ let cask = try #require(try casks().first { $0.kind == .cask })
+ #expect(cask.commandLinks == ["/opt/homebrew/bin/pearcleaner"])
+ #expect(cask.appTargets == ["/Applications/Pearcleaner.app"], "a command's link was read as the app's place")
+
+ let notInstalled = #"{"binary": ["$APPDIR/Pearcleaner.app/Contents/MacOS/Pearcleaner", {"target": "pearcleaner"}]}"#
+ let known = try JSONDecoder().decode(CaskArtifact.self, from: Data(notInstalled.utf8))
+ #expect(known.commandLinks.isEmpty)
+ }
+
@Test func readsAppsAndLeftoverPathsFromACask() throws {
let cask = try #require(try casks().first { $0.kind == .cask })
#expect(cask.name == "pearcleaner")
diff --git a/Peel/PeelApp.swift b/Peel/PeelApp.swift
index 2d3bf8a3..5818413b 100644
--- a/Peel/PeelApp.swift
+++ b/Peel/PeelApp.swift
@@ -244,6 +244,7 @@ struct PeelApp: App {
.environment(trashMonitor)
.environment(exclusions)
.environment(library)
+ .environment(homebrew)
.environment(history)
.environment(home)
}
diff --git a/Peel/Views/Settings/SettingsView.swift b/Peel/Views/Settings/SettingsView.swift
index 9e361ce9..6fb28c6d 100644
--- a/Peel/Views/Settings/SettingsView.swift
+++ b/Peel/Views/Settings/SettingsView.swift
@@ -82,6 +82,7 @@ private struct GeneralSettingsView: View {
@Environment(TrashMonitor.self) private var trashMonitor
@Environment(\.scenePhase) private var scenePhase
@Environment(AppLibrary.self) private var library
+ @Environment(HomebrewLibrary.self) private var homebrew
@Environment(HelperModel.self) private var helper
@Environment(RemovalHistoryStore.self) private var history
@Environment(HomeModel.self) private var home
@@ -244,22 +245,42 @@ private struct GeneralSettingsView: View {
SavedSettingsSection()
Section {
- // The button is taller than a row, and `LabeledContent` would align the title with its top
- // edge. An `HStack` centers the title and the button vertically.
- HStack {
- titled("Remove Peel",
- "Peel removes its helper and login item, moves itself, the files that are certainly its own, and its folder in Application Support to the Trash, clears its settings, then quits. That folder holds History, your exclusions, and Saved Settings. The Finder extension goes with the app.")
- Spacer(minLength: 8)
- Button("Remove Peel", systemImage: "trash") {
- isConfirmingSelfRemoval = true
+ // Homebrew lists the copy it installed until `brew uninstall` removes it.
+ if let cask = ownCask {
+ let command = "brew uninstall --zap --cask \(cask.name)"
+ LabeledContent {
+ CopyButton(text: command)
+ } label: {
+ titled("Remove Peel",
+ "Homebrew installed this copy of Peel, so remove it with Homebrew, or Homebrew goes on listing it as installed. Run the command in Terminal: Homebrew deletes the app rather than moving it to the Trash, and moves Peel’s files to the Trash, its folder in Application Support among them. That folder holds History, your exclusions, and Saved Settings.")
+ }
+ Text(verbatim: command)
+ .font(.caption.monospaced())
+ .foregroundStyle(.secondary)
+ .textSelection(.enabled)
+ } else {
+ // The button is taller than a row, and `LabeledContent` would align the title with its top
+ // edge. An `HStack` centers the title and the button vertically.
+ HStack {
+ titled("Remove Peel",
+ "Peel removes its helper and login item, moves itself, the files that are certainly its own, and its folder in Application Support to the Trash, clears its settings, then quits. That folder holds History, your exclusions, and Saved Settings. The Finder extension goes with the app.")
+ Spacer(minLength: 8)
+ Button("Remove Peel", systemImage: "trash") {
+ isConfirmingSelfRemoval = true
+ }
+ .buttonStyle(.borderedProminent)
+ .tint(.red)
+ // Disabled until the app list and Homebrew's have loaded: without the first, a file Peel
+ // shares with another app would look like Peel's alone, and without the second, a copy
+ // Homebrew installed would look like one it didn't.
+ .disabled(
+ selfUninstall.isRunning || !library.hasLoaded
+ || (homebrew.isInstalled && homebrew.packages == nil)
+ )
}
- .buttonStyle(.borderedProminent)
- .tint(.red)
- // Disabled until the app list has loaded: without it, a file Peel shares with another app
- // would look like Peel's alone.
- .disabled(selfUninstall.isRunning || !library.hasLoaded)
}
- if selfUninstall.hasCommandLineTool {
+ // Homebrew removes the links its cask made, and no other.
+ if selfUninstall.hasCommandLineTool, ownCask?.commandLinks.contains(CommandLineTool.path) != true {
Text("Removing Peel leaves the peel command in place. To remove it too, run: \(Text(verbatim: SelfUninstall.removeCommand).font(.caption.monospaced()))")
.font(.callout)
.foregroundStyle(.secondary)
@@ -386,6 +407,13 @@ extension GeneralSettingsView {
set: { if !$0 { selfUninstall.failure = nil } }
)
}
+
+ /// The cask Homebrew installed this copy of Peel from, found by the rule the Applications list follows.
+ fileprivate var ownCask: HomebrewPackage? {
+ let own = PathPattern.comparablePath(of: Bundle.main.bundleURL)
+ guard let app = library.apps.first(where: { PathPattern.comparablePath(of: $0.url) == own }) else { return nil }
+ return CaskEvidence.installedCask(for: app, in: (homebrew.packages ?? []).filter { $0.kind == .cask })
+ }
}
private struct HelperSettingsView: View {
diff --git a/README.md b/README.md
index d16a4c85..6106babb 100644
--- a/README.md
+++ b/README.md
@@ -336,13 +336,16 @@ In Settings > General, choose Remove Peel. It removes its helper and its login i
are certainly its own, and its folder in Application Support to the Trash, clears its settings, and quits. That
folder holds History, your exclusions, and the settings Peel saved when you reset an app.
-If you installed Peel with Homebrew, run this instead, which also removes Peel's files:
+If you installed Peel with Homebrew, Settings shows this command in its place, with a button that copies it. Run it
+in Terminal: Homebrew takes Peel off its list of what is installed, deletes the app rather than moving it to the
+Trash, and moves Peel's files to the Trash.
```bash
brew uninstall --zap --cask peel
```
-If you put the `peel` command on your path from Settings, remove it too:
+If you put the `peel` command on your path from Settings, remove that link too. Homebrew removes only the one it
+made.
```bash
sudo rm -f /usr/local/bin/peel