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
Put a name beginning with a dash after -- in the command peel offers to copy
Țugui Dragoșa3c90f16f0bd
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex eb793b57..cd180092 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -208,7 +208,8 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.#### `peel`-- A name beginning with `-` or `=` is quoted in a command `peel` offers to copy, so pasting it works.+- The command `peel uninstall` offers to copy works for an app whose name begins with `-` or `=`: the name comes last,+ quoted where a shell would read it otherwise, and after `--` when it begins with `-`, so it isn't read as an option.### Securitydiff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swiftindex 987b0bc7..ee8aa435 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift@@ -695,7 +695,7 @@ struct UninstallCommand: AsyncParsableCommand {}if plan.needsReview > 0 {let them = plan.needsReview == 1 ? "it" : "them"- notes.append("\(Output.count(plan.needsReview, "file needs", "files need")) review and will stay. See \(them) with `peel leftovers \(Output.quoted(app.name)) --all`.")+ notes.append("\(Output.count(plan.needsReview, "file needs", "files need")) review and will stay. See \(them) with `peel leftovers --all \(Output.lastArgument(app.name))`.")}return notes}diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swiftindex 60371df7..e8bdd113 100644--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift@@ -52,15 +52,21 @@ enum Output {}/// Returns `name` so the reader can paste it into a command: in single quotes unless every character is a- /// letter, a digit, or one of `._/+-@%:=,`, which no shell reads as anything but itself, and the first is- /// neither `-`, an option to `peel`, nor `=`, a command name to zsh.+ /// letter, a digit, or one of `._/+-@%:=,`, which no shell reads as anything but itself, and the first is not+ /// `=`, which zsh reads as a command's path.static func quoted(_ name: String) -> String {let name = plain(name)let isPlain = !name.isEmpty && name.allSatisfy { $0.isLetter || $0.isNumber || "._/+-@%:=,".contains($0) }- && !"-=".contains(name.first ?? " ")+ && name.first != "="return isPlain ? name : "'\(name.replacingOccurrences(of: "'", with: "'\\''"))'"}+ /// Returns `name` as the last argument of a command to paste, quoted, and after `--` when it begins with `-`,+ /// which `peel` would otherwise read as options whatever the quotes.+ static func lastArgument(_ name: String) -> String {+ plain(name).hasPrefix("-") ? "-- " + quoted(name) : quoted(name)+ }+/// Writes `text` to standard output unchanged, for output that already ends in a newline. When the write fails/// (a full disk, a closed stdout), the tool exits with status 1. `FileHandle.write(_:)` would instead raise an/// exception Swift can't catch, and the tool would crash. A pipe whose reader has gone ends the process withdiff --git a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swiftindex da215848..a9aacca1 100644--- a/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift+++ b/Packages/PeelCore/Tests/PeelCoreTests/CommandLineTests.swift@@ -551,12 +551,16 @@ struct CommandLineTests {#expect(Output.quoted("Editor") == "Editor")#expect(Output.quoted("Sam's Apps") == "'Sam'\\''s Apps'")let breaking = [- "Q&A", "Tools;Kit", "A|B", "(Beta)", "Cost$", "Back`tick", "Star*", "What?", "Wow!", "No#1", "-Dash", "=Equal",+ "Q&A", "Tools;Kit", "A|B", "(Beta)", "Cost$", "Back`tick", "Star*", "What?", "Wow!", "No#1", "=Equal",]for name in breaking + ["Sam's"] {#expect(Output.quoted(name).hasPrefix("'"), "\(name) would break the command it is pasted into")}#expect(Output.quoted("Café-2.0_x86/64+@%:=,") == "Café-2.0_x86/64+@%:=,")+ #expect(Output.lastArgument("Editor") == "Editor")+ #expect(Output.lastArgument("Notes Pro") == "'Notes Pro'")+ #expect(Output.lastArgument("-Dash") == "-- -Dash")+ #expect(Output.lastArgument("-Dash Pro") == "-- '-Dash Pro'")}// MARK: peel uninstall@@ -631,7 +635,22 @@ struct CommandLineTests {#expect(notes[1] == Output.fullDiskAccessNote)#expect(notes[2].hasPrefix("There are more folders in /Users/me/Library/Caches than Peel looks inside"))#expect(notes[3] == "1 item needs administrator access and will stay. Remove it with the Peel app.")- #expect(notes[4] == "1 file needs review and will stay. See it with `peel leftovers Editor --all`.")+ #expect(notes[4] == "1 file needs review and will stay. See it with `peel leftovers --all Editor`.")+ }++ @Test func offersACommandThatReadsANameBeginningWithADashAsTheApp() {+ let app = InstalledApp(+ url: URL(filePath: "/Applications/-Dash.app", directoryHint: .isDirectory),+ bundleIdentifier: "org.example.dash", name: "-Dash"+ )+ let review = leftover(URL(filePath: "/Users/me/Library/Caches/review"), heldBack: .namedLikeTheApp)+ let plan = UninstallPlan.make(uninstallation(app: app, leftovers: [review]), keepLeftovers: false) { _ in nil }++ let notes = UninstallCommand.whatStays(+ plan, app: app, homebrew: CaskLookup.Answer(), scan: LeftoverScan(leftovers: [], unreadableLocations: [])+ )++ #expect(notes == ["1 file needs review and will stay. See it with `peel leftovers --all -- -Dash`."])}@Test func saysWhereWhatOnlyAnAdministratorCanMoveIsListed() throws {@@ -653,7 +672,7 @@ struct CommandLineTests {)#expect(notes == ["1 item needs an administrator, and Peel's helper isn't allowed to move it. Once Editor is in the Trash, Orphaned Files in the Peel app lists it under Needs an Administrator, with how to remove it.",- "1 file needs review and will stay. See it with `peel leftovers Editor --all`.",+ "1 file needs review and will stay. See it with `peel leftovers --all Editor`.",])#expect(UninstallPlan.make(editor, keepLeftovers: true, refusal: { _ in nil }).leftForAnAdministrator == 1)let json = try Output.jsonText(