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.

Name the lines of the shell startup files that still point to what moved

Țugui Dragoș974e42e2999a
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 687b4a74..48ca0766 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -148,7 +148,9 @@ the Homebrew page's uninstall and cleanups are Homebrew's own.
forget the preference domains whose files went, and an uninstalled app's Dock icon comes out (`DockTiles`),
unless Also remove from the Dock was turned off, or `peel uninstall` was given `--keep-in-dock`. On macOS 27,
an app's page and several apps' page also say when macOS still starts the app's login items at login, now from
- the Trash, until the Trash is emptied (`TrashResult.startsFromTheTrash`).
+ the Trash, until the Trash is emptied (`TrashResult.startsFromTheTrash`). Both pages, and `peel uninstall`, also
+ name the lines of the shell startup files that still point to what moved, such as a `PATH` entry into the app
+ (`ShellReferences`, which reads the files zsh, bash, and fish start with and never changes them).
7. **Record.**
- Every removal goes into History (`removals.json`, through `RemovalLog`), with where each item came from and
where it went, so it can be put back; History keeps the most recent 20,000 items. A removal is one entry,
diff --git a/GUIDE.md b/GUIDE.md
index 6236311a..61407b90 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -64,6 +64,10 @@ and how to get it, [SAFETY.md](SAFETY.md) what it protects, [PRIVACY.md](PRIVACY
unless you deselect it, and History puts it back where it was when you put the app back.
- **When macOS needs more.** After a removal, Peel says when macOS keeps using what moved: an audio driver until
you restart your Mac, and, on macOS 27, an app's login items, which macOS starts from the Trash until you empty it.
+- **Lines that still point to what moved.** After a removal, Peel reads the files your shell runs when it starts
+ (`.zshrc` and the others zsh, bash, and fish read) and names each line that still points to what moved, such as a
+ `PATH` entry or an alias into the app, so a new shell stops printing an error once you edit it. Peel changes none
+ of these files.
- **What it opens.** An app's page lists the kinds of files and links it opens by default, and what would open
them once it's gone. Peel never changes that itself.
- **Updates for your apps.** Peel checks your apps for new versions, through the update feed each app names, the
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 402ccd41..3ba14495 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -5482,6 +5482,112 @@
}
}
},
+ "%@, line %lld" : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, řádek %lld"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, Zeile %lld"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, línea %lld"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, ligne %lld"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, riga %lld"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@の%lld行目"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@의 %lld번째 줄"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, regel %lld"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, wiersz %lld"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, linha %lld"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, linia %lld"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, строка %lld"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, rad %lld"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, %lld. satır"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@, рядок %lld"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@,第%lld行"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "%@的第%lld行"
+ }
+ }
+ }
+ },
"%@, update available: %@" : {
"localizations" : {
"cs" : {
@@ -188568,6 +188674,218 @@
}
}
},
+ "Your shell files still name what moved." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Soubory vašeho shellu stále odkazují na to, co se přesunulo."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Die Dateien deiner Shell verweisen noch auf das, was verschoben wurde."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Los archivos de tu shell siguen mencionando lo que se ha trasladado."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Les fichiers de votre shell font encore référence à ce qui a été déplacé."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "I file della tua shell fanno ancora riferimento a ciò che è stato spostato."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "シェルのファイルには、ゴミ箱に入れた項目のパスがまだ残っています。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "셸 파일에 휴지통으로 이동한 항목의 경로가 아직 남아 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "De bestanden van je shell verwijzen nog naar wat is verplaatst."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Pliki Twojej powłoki nadal odwołują się do tego, co przeniesiono do Kosza."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Os arquivos do seu shell ainda apontam para o que foi movido."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Fișierele shellului dvs. încă fac referire la ce s‑a mutat."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "В файлах Вашей оболочки еще остались пути к тому, что перемещено в Корзину."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kommandotolkens startfiler hänvisar fortfarande till det som flyttades."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kabuk dosyalarınız hâlâ Çöp Sepeti’ne taşınanlara işaret ediyor."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Файли вашої оболонки досі посилаються на те, що переміщено."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "你的shell文件仍引用已移走的项目。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "你的Shell檔案仍指向已移動的項目。"
+ }
+ }
+ }
+ },
+ "Your shell startup files still name what moved, at %@. Peel reads these files and never changes them." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Soubory, které váš shell načítá při spuštění, stále odkazují na to, co se přesunulo: %@. Peel tyto soubory jen čte a nikdy je nemění."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Die Startdateien deiner Shell verweisen noch auf das, was verschoben wurde, und zwar in %@. Peel liest diese Dateien nur und ändert sie nie."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Los archivos de inicio de tu shell siguen mencionando lo que se ha trasladado, en %@. Peel lee estos archivos y nunca los cambia."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Les fichiers que votre shell lit à son démarrage font encore référence à ce qui a été déplacé, dans %@. Peel lit ces fichiers et ne les modifie jamais."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "I file di avvio della tua shell fanno ancora riferimento a ciò che è stato spostato, in %@. Peel legge questi file e non li modifica mai."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "シェルの起動時に読み込まれるファイルには、ゴミ箱に入れた項目のパスがまだ残っています(%@)。Peelはこれらのファイルを読み取るだけで、変更することは決してありません。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "셸 시작 파일 %@에 휴지통으로 이동한 항목의 경로가 아직 남아 있습니다. Peel은 이 파일을 읽기만 하며 절대 변경하지 않습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "De opstartbestanden van je shell verwijzen nog naar wat is verplaatst: %@. Peel leest deze bestanden en wijzigt ze nooit."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Pliki startowe Twojej powłoki nadal odwołują się do tego, co przeniesiono do Kosza, w następujących miejscach: %@. Peel tylko odczytuje te pliki i nigdy ich nie zmienia."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Os arquivos de inicialização do seu shell ainda apontam para o que foi movido, em %@. O Peel lê esses arquivos e nunca os altera."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Fișierele pe care shellul dvs. le citește la pornire încă fac referire la ce s‑a mutat, în %@. Peel citește aceste fișiere și nu le modifică niciodată."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Пути к тому, что перемещено в Корзину, еще остались в файлах, которые Ваша оболочка читает при запуске: %@. Peel только читает эти файлы и никогда их не меняет."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kommandotolkens startfiler hänvisar fortfarande till det som flyttades, i %@. Peel läser de här filerna men ändrar dem aldrig."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Kabuğunuzun başlangıç dosyaları hâlâ Çöp Sepeti’ne taşınanlara işaret ediyor: %@. Peel bu dosyaları yalnızca okur, hiçbir zaman değiştirmez."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Файли, які ваша оболонка читає під час запуску, досі посилаються на те, що переміщено: %@. Peel лише читає ці файли й ніколи їх не змінює."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "你的shell启动文件仍引用已移走的项目,位于%@。Peel只会读取这些文件,绝不会更改它们。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "你的Shell啟動檔案仍指向已移動的項目,位於%@。Peel會讀取這些檔案,但絕不會更改它們。"
+ }
+ }
+ }
+ },
"You’re all set" : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 10c4048e..fcd5c370 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -307,6 +307,13 @@ struct UninstallCommand: AsyncParsableCommand {
let needsReview: Int
let leftForAnAdministrator: Int
let unreadableLocations: [String]
+ /// The lines of the shell startup files that still name what moved.
+ let shellReferences: [ShellReference]
+
+ struct ShellReference: Encodable {
+ let file: String
+ let line: Int
+ }
private enum CodingKeys: String, CodingKey {
case app
@@ -320,6 +327,7 @@ struct UninstallCommand: AsyncParsableCommand {
case needsReview
case leftForAnAdministrator
case unreadableLocations
+ case shellReferences
}
/// Encodes an unknown `privacyReset` and `appMoved` as `null`, for the reason `AppRecord` gives.
@@ -336,6 +344,7 @@ struct UninstallCommand: AsyncParsableCommand {
try container.encode(needsReview, forKey: .needsReview)
try container.encode(leftForAnAdministrator, forKey: .leftForAnAdministrator)
try container.encode(unreadableLocations, forKey: .unreadableLocations)
+ try container.encode(shellReferences, forKey: .shellReferences)
}
}
@@ -345,7 +354,8 @@ struct UninstallCommand: AsyncParsableCommand {
plan: UninstallPlan,
result: TrashResult?,
privacy: PrivacyReset.Result?,
- unreadable: [SearchLocation]
+ unreadable: [SearchLocation],
+ shellReferences: [ShellReferences.Reference] = []
) -> Report {
Report(
app: AppRecord(app),
@@ -362,7 +372,8 @@ struct UninstallCommand: AsyncParsableCommand {
needsAdministrator: plan.needsAdministrator,
needsReview: plan.needsReview,
leftForAnAdministrator: plan.leftForAnAdministrator,
- unreadableLocations: unreadable.map { Output.path($0.url) }
+ unreadableLocations: unreadable.map { Output.path($0.url) },
+ shellReferences: shellReferences.map { Report.ShellReference(file: Output.path($0.file), line: $0.line) }
)
}
@@ -620,9 +631,13 @@ struct UninstallCommand: AsyncParsableCommand {
if isInTheDock, Self.takesOutDockIcon(of: target, after: result, keeping: keepInDock) {
_ = await DockTiles().takeOut([target.url])
}
+ let references = await ShellReferences.find(naming: result.trashed.map(\.originalURL))
if output.json {
- let report = Self.report(app: target, plan: plan, result: result, privacy: reset, unreadable: unreadable)
+ let report = Self.report(
+ app: target, plan: plan, result: result, privacy: reset, unreadable: unreadable,
+ shellReferences: references
+ )
try Output.json(report)
if let privacy, privacy.failed {
Output.note(privacy.line)
@@ -636,6 +651,10 @@ struct UninstallCommand: AsyncParsableCommand {
if let note = Self.startsFromTheTrashNote(for: target, after: result) {
Output.note(note)
}
+ if !references.isEmpty {
+ let places = references.map { "\(Output.plain(Output.path($0.file))):\($0.line)" }.joined(separator: ", ")
+ Output.note("Your shell startup files still name what moved, at \(places). Peel reads them and never changes them.")
+ }
if !recorded {
Output.note("Peel couldn't write this to its History, so drag these back out of the Trash in Finder if you need to.")
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/ShellReferences.swift b/Packages/PeelCore/Sources/PeelCore/Removal/ShellReferences.swift
new file mode 100644
index 00000000..7d66122d
--- /dev/null
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/ShellReferences.swift
@@ -0,0 +1,71 @@
+public import Foundation
+
+/// The lines of the shell startup files that still name something a removal moved, such as a path exported or
+/// sourced from inside an app's bundle. Peel reads these files and never changes them: it points to the line.
+public enum ShellReferences {
+ public struct Reference: Sendable, Hashable {
+ public let file: URL
+ public let line: Int
+
+ public init(file: URL, line: Int) {
+ self.file = file
+ self.line = line
+ }
+ }
+
+ /// At most this much of a startup file is read; a bigger one is passed over.
+ static let maximumBytes = 1_048_576
+
+ @concurrent
+ public static func find(naming moved: [URL], home: URL = .homeDirectory) async -> [Reference] {
+ let spellings = moved.flatMap { spellings(of: $0, home: home) }
+ guard !spellings.isEmpty else { return [] }
+ var references: [Reference] = []
+ for file in await startupFiles(home: home) {
+ guard let data = BoundedRead.data(at: file, maximum: maximumBytes) else { continue }
+ let lines = String(decoding: data, as: UTF8.self).split(separator: "\n", omittingEmptySubsequences: false)
+ for (index, line) in lines.enumerated() where !line.drop(while: \.isWhitespace).hasPrefix("#") {
+ if spellings.contains(where: { line.range(of: $0, options: .caseInsensitive) != nil }) {
+ references.append(Reference(file: file, line: index + 1))
+ }
+ }
+ }
+ return references
+ }
+
+ /// The files zsh, bash and fish read when a shell starts: zsh's `.zshenv` where the session's ZDOTDIR or the
+ /// home folder puts it, the other three in the folder zsh names once `.zshenv` has run, and the rest in the home
+ /// folder.
+ static func startupFiles(home: URL) async -> [URL] {
+ var files: [URL] = []
+ let zdotdir = ShellSessions.sessionZDOTDIR
+ if let zsh = ShellSessions.of(terminalSetting: nil, loginShell: "/bin/zsh", zdotdir: zdotdir, home: home),
+ case .zsh(let zshenv) = zsh {
+ files.append(zshenv)
+ let folder = (await zsh.zshrc(home: home, zdotdir: zdotdir) ?? zshenv).deletingLastPathComponent()
+ files += [".zprofile", ".zshrc", ".zlogin"].map { folder.appending(path: $0, directoryHint: .notDirectory) }
+ }
+ files += [".bash_profile", ".bashrc", ".profile", ".config/fish/config.fish"].map {
+ home.appending(path: $0, directoryHint: .notDirectory)
+ }
+ var seen: Set<String> = []
+ return files.filter { seen.insert($0.path(percentEncoded: false)).inserted }
+ }
+
+ /// A path as a shell line writes it: whole, or with `~` or `$HOME` for the home folder, each also with its
+ /// spaces escaped.
+ static func spellings(of url: URL, home: URL) -> [String] {
+ let path = trimmed(url.path(percentEncoded: false))
+ let homePath = trimmed(home.path(percentEncoded: false))
+ var spellings = [path]
+ if path.hasPrefix(homePath + "/") {
+ let rest = path.dropFirst(homePath.count)
+ spellings += ["~" + rest, "$HOME" + rest, "${HOME}" + rest]
+ }
+ return spellings + spellings.filter { $0.contains(" ") }.map { $0.replacingOccurrences(of: " ", with: "\\ ") }
+ }
+
+ private static func trimmed(_ path: String) -> String {
+ path.count > 1 && path.hasSuffix("/") ? String(path.dropLast()) : path
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
index 0df06d58..7dbbed9b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift
@@ -487,6 +487,16 @@ struct CommandLineTests {
#expect(report["needsAdministrator"] as? Int == 1)
#expect(report["needsReview"] as? Int == 2)
#expect(report["unreadableLocations"] as? [String] == [])
+ #expect((report["shellReferences"] as? [Any])?.isEmpty == true)
+
+ let named = try Output.jsonText(UninstallCommand.report(
+ app: editor, plan: plan, result: result, privacy: nil, unreadable: [],
+ shellReferences: [ShellReferences.Reference(file: URL(filePath: "/Users/me/.zshrc"), line: 12)]
+ ))
+ let shell = try #require(JSONSerialization.jsonObject(with: Data(named.utf8)) as? [String: Any])
+ let references = try #require(shell["shellReferences"] as? [[String: Any]])
+ #expect(references.map { $0["file"] as? String } == ["/Users/me/.zshrc"])
+ #expect(references.map { $0["line"] as? Int } == [12])
let dryRun = try Output.jsonText(
UninstallCommand.report(app: editor, plan: plan, result: nil, privacy: nil, unreadable: [])
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ShellReferencesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ShellReferencesTests.swift
new file mode 100644
index 00000000..c8a57e74
--- /dev/null
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ShellReferencesTests.swift
@@ -0,0 +1,50 @@
+import Foundation
+@testable import PeelCore
+import Testing
+
+struct ShellReferencesTests {
+ @Test func namesTheLinesThatStillPointToWhatMoved() async throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ try directory.file("home/.zshrc", contents: Data("""
+ # export PATH="/Applications/Note Pad.app/Contents/MacOS:$PATH"
+ export PATH="/Applications/Note Pad.app/Contents/MacOS:$PATH"
+ alias notes="$HOME/Library/Application Support/Note Pad/notes"
+ source ~/Library/Application\\ Support/Note\\ Pad/env.sh
+ export EDITOR=vim
+ """.utf8))
+ try directory.file("home/.config/fish/config.fish", contents: Data("set -gx NOTES ~/Library/Application Support/Note Pad\n".utf8))
+ try directory.file("home/.bashrc", contents: Data("export PATH=/opt/other/bin:$PATH\n".utf8))
+ let moved = [
+ URL(filePath: "/Applications/Note Pad.app", directoryHint: .isDirectory),
+ home.appending(path: "Library/Application Support/Note Pad", directoryHint: .isDirectory),
+ ]
+
+ let found = await ShellReferences.find(naming: moved, home: home)
+
+ #expect(found.map { ($0.file.lastPathComponent, $0.line) }.map { "\($0.0):\($0.1)" } == [
+ ".zshrc:2", ".zshrc:3", ".zshrc:4", "config.fish:1",
+ ])
+ #expect(await ShellReferences.find(naming: [], home: home).isEmpty)
+ }
+
+ @Test func readsTheStartupFilesOfEachShellOnce() async throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ try directory.directory("home")
+
+ let files = await ShellReferences.startupFiles(home: home).map(\.lastPathComponent)
+
+ #expect(files == [".zshenv", ".zprofile", ".zshrc", ".zlogin", ".bash_profile", ".bashrc", ".profile", "config.fish"])
+ #expect(Set(files).count == files.count)
+ }
+
+ @Test func spellsAPathAsAShellLineWould() {
+ let home = URL(filePath: "/Users/me", directoryHint: .isDirectory)
+ #expect(ShellReferences.spellings(of: URL(filePath: "/Applications/Pad.app/"), home: home) == ["/Applications/Pad.app"])
+ #expect(ShellReferences.spellings(of: URL(filePath: "/Users/me/Library/Pad Data"), home: home) == [
+ "/Users/me/Library/Pad Data", "~/Library/Pad Data", "$HOME/Library/Pad Data", "${HOME}/Library/Pad Data",
+ "/Users/me/Library/Pad\\ Data", "~/Library/Pad\\ Data", "$HOME/Library/Pad\\ Data", "${HOME}/Library/Pad\\ Data",
+ ])
+ }
+}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/StringCatalogTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/StringCatalogTests.swift
index 881e1399..645fe81b 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/StringCatalogTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/StringCatalogTests.swift
@@ -384,7 +384,7 @@ struct CatalogChecker {
/// The languages whose macOS writes App Store with a no-break space, so a line never breaks inside the name.
static let appStoreHeldTogether: Set<String> = ["cs", "de", "es", "fr", "ko", "nl", "pl", "ru", "uk"]
/// Keys whose numbers are positions, with no word that changes with them, so they need no plural variation.
- static let countsWithoutAgreement: Set<String> = ["Step %lld of %lld"]
+ static let countsWithoutAgreement: Set<String> = ["Step %lld of %lld", "%@, line %lld"]
/// Languages where `one` covers more than 1, so a `one` form without the number would also show for other
/// counts. In French and Portuguese 0 takes `one`, and in Russian and Ukrainian 21 and 101 do.
static let oneIsMoreThanOne: Set<String> = ["fr", "pt", "ru", "uk"]
diff --git a/Peel/Model/RemovalOutcome.swift b/Peel/Model/RemovalOutcome.swift
index 6bd76bd6..f5ed6552 100644
--- a/Peel/Model/RemovalOutcome.swift
+++ b/Peel/Model/RemovalOutcome.swift
@@ -25,11 +25,13 @@ final class RemovalOutcome {
private(set) var appsStartingFromTheTrash: [String] = []
/// How many of the items the removal left stay for an administrator, which Orphaned Files lists.
private(set) var leftForAnAdministrator = 0
+ /// The lines of the shell startup files that still name what moved, which the person edits.
+ private(set) var shellReferences: [ShellReferences.Reference] = []
private(set) var movedCount = 0
var isEmpty: Bool {
failures.isEmpty && privacy.isEmpty && appsToQuit.isEmpty && driversAwaitingARestart.isEmpty
- && appsStartingFromTheTrash.isEmpty && leftForAnAdministrator == 0
+ && appsStartingFromTheTrash.isEmpty && leftForAnAdministrator == 0 && shellReferences.isEmpty
}
/// Keeps what the removal could not do, what a restart or an emptied Trash finishes, and what stays for an
@@ -41,7 +43,8 @@ final class RemovalOutcome {
appsToQuit: [String] = [],
keptTheirFiles: [String] = [],
startingFromTheTrash: [String] = [],
- leftForAnAdministrator: Int = 0
+ leftForAnAdministrator: Int = 0,
+ shellReferences: [ShellReferences.Reference] = []
) {
let privacy = PrivacyReset.worthTelling(resets, after: result).map {
Privacy(app: $0.app.name, result: $0.result)
@@ -49,7 +52,7 @@ final class RemovalOutcome {
let drivers = AudioDrivers.awaitingARestart(after: result)
guard
!result.failures.isEmpty || !privacy.isEmpty || !appsToQuit.isEmpty || !drivers.isEmpty
- || !startingFromTheTrash.isEmpty || leftForAnAdministrator > 0
+ || !startingFromTheTrash.isEmpty || leftForAnAdministrator > 0 || !shellReferences.isEmpty
else { return }
failures = result.failures
movedCount = result.trashed.count
@@ -58,6 +61,7 @@ final class RemovalOutcome {
self.keptTheirFiles = keptTheirFiles
driversAwaitingARestart = drivers
self.leftForAnAdministrator = leftForAnAdministrator
+ self.shellReferences = shellReferences
// Two copies of an app share its name and its background items.
var named: Set<String> = []
appsStartingFromTheTrash = startingFromTheTrash.filter { named.insert($0).inserted }
@@ -72,5 +76,6 @@ final class RemovalOutcome {
driversAwaitingARestart = []
appsStartingFromTheTrash = []
leftForAnAdministrator = 0
+ shellReferences = []
}
}
diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swift
index 43e867a2..dfe8fe24 100644
--- a/Peel/Views/AppDetailView.swift
+++ b/Peel/Views/AppDetailView.swift
@@ -489,7 +489,8 @@ struct AppDetailView: View {
privacy: privacy,
keptTheirFiles: keptItsFiles ? [plan.app.name] : [],
startingFromTheTrash: result.startsFromTheTrash.contains(plan.app.url) ? [plan.app.name] : [],
- leftForAnAdministrator: left.count
+ leftForAnAdministrator: left.count,
+ shellReferences: await ShellReferences.find(naming: result.trashed.map(\.originalURL))
)
if plan.removesDockTile, result.trashed.contains(where: { $0.originalURL == plan.app.url }) {
_ = await DockTiles().takeOut([plan.app.url])
diff --git a/Peel/Views/MultipleAppsView.swift b/Peel/Views/MultipleAppsView.swift
index 2960a53d..9cadf037 100644
--- a/Peel/Views/MultipleAppsView.swift
+++ b/Peel/Views/MultipleAppsView.swift
@@ -365,7 +365,8 @@ struct MultipleAppsView: View {
privacy: privacy,
keptTheirFiles: kept.map(\.name),
startingFromTheTrash: plan.apps.filter { result.startsFromTheTrash.contains($0.url) }.map(\.name),
- leftForAnAdministrator: left.count
+ leftForAnAdministrator: left.count,
+ shellReferences: await ShellReferences.find(naming: result.trashed.map(\.originalURL))
)
if plan.removesDockTiles {
let moved = Set(result.trashed.map(\.originalURL))
diff --git a/Peel/Views/RemovalFailureAlert.swift b/Peel/Views/RemovalFailureAlert.swift
index ed96495c..db0b984d 100644
--- a/Peel/Views/RemovalFailureAlert.swift
+++ b/Peel/Views/RemovalFailureAlert.swift
@@ -62,6 +62,11 @@ struct RemovalFailureAlert: ViewModifier {
outcome.driversAwaitingARestart.isEmpty, outcome.leftForAnAdministrator > 0 {
return Text("Some items stayed for an administrator.")
}
+ if outcome.failures.isEmpty, outcome.appsToQuit.isEmpty, outcome.privacy.isEmpty,
+ outcome.driversAwaitingARestart.isEmpty, outcome.appsStartingFromTheTrash.isEmpty,
+ !outcome.shellReferences.isEmpty {
+ return Text("Your shell files still name what moved.")
+ }
if outcome.failures.isEmpty, outcome.appsToQuit.isEmpty, outcome.privacy.isEmpty {
return Text("Restart your Mac to finish.")
}
@@ -78,7 +83,7 @@ struct RemovalFailureAlert: ViewModifier {
if rest > 0 {
lines.append(String(inflecting: "And ^[\(rest) more item](inflect: true)."))
}
- lines += keptLines + driverLines + administratorLines + extraLines
+ lines += keptLines + driverLines + administratorLines + shellLines + extraLines
if #available(macOS 27, *) {
lines += trashLines
}
@@ -93,6 +98,14 @@ struct RemovalFailureAlert: ViewModifier {
: [String(inflecting: "^[\(count) item](inflect: true) stayed because only an administrator can move them, and Peel’s helper isn’t allowed to. Orphaned Files lists them under Needs an Administrator, with how to remove them.")]
}
+ /// One line for the shell startup files that still name what moved: the person edits them, Peel never does.
+ private var shellLines: [String] {
+ let references = outcome.shellReferences
+ guard !references.isEmpty else { return [] }
+ let places = references.map { String(localized: "\($0.file.abbreviatedPath), line \($0.line)") }
+ return [String(localized: "Your shell startup files still name what moved, at \(places.formatted(.list(type: .and))). Peel reads these files and never changes them.")]
+ }
+
private var driverLines: [String] {
let drivers = outcome.driversAwaitingARestart
guard !drivers.isEmpty else { return [] }
diff --git a/PeelTests/RemovalOutcomeTests.swift b/PeelTests/RemovalOutcomeTests.swift
new file mode 100644
index 00000000..cec5b020
--- /dev/null
+++ b/PeelTests/RemovalOutcomeTests.swift
@@ -0,0 +1,19 @@
+import Foundation
+@testable import Peel
+import PeelCore
+import Testing
+
+struct RemovalOutcomeTests {
+ @Test func tellsOfShellFilesThatStillNameWhatMoved() {
+ let outcome = RemovalOutcome()
+ let reference = ShellReferences.Reference(file: URL(filePath: "/Users/me/.zshrc"), line: 12)
+
+ outcome.report(TrashResult(), shellReferences: [reference])
+ #expect(!outcome.isEmpty && outcome.shellReferences == [reference])
+ outcome.report(TrashResult())
+ #expect(outcome.shellReferences == [reference], "a removal with nothing to tell changes nothing")
+
+ outcome.clear()
+ #expect(outcome.isEmpty)
+ }
+}
diff --git a/SECURITY.md b/SECURITY.md
index 050705cb..399409ae 100644
--- a/SECURITY.md
+++ b/SECURITY.md
@@ -162,7 +162,8 @@ have, and anything that destroys data that cannot be recovered.
messaging manifest, the package definitions Homebrew and its taps give, whose paths an uninstall
lists, Homebrew's own `brew.env` files, Terminal's preferences, the settings files of the tools whose
caches Developer lists (`.npmrc`, `.yarnrc`, `.yarnrc.yml`, pnpm's `config.yaml`, Go's `env`), which
- say where a cache was moved, and the database macOS keeps of where downloads came from, read for
+ say where a cache was moved, the shell startup files, read after a removal for the lines that still
+ name what moved, and the database macOS keeps of where downloads came from, read for
`peel inventory` and Export. One that causes memory corruption, an exploitable crash, or a wrong
answer about what may be removed is in scope.
- The programs Peel runs with what a scan found: `defaults`, `launchctl`, `tccutil`, `pkgutil`, and