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.

Wrap the long lines of the peel tool and of peel links at 120 columns

Țugui Dragoșf0c8db7815e0
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
index 858a39bf..6575f969 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/AppCommands.swift
@@ -508,7 +508,12 @@ struct UninstallCommand: AsyncParsableCommand {
/// Returns the notes printed before the question: what the scan couldn't fully check, and files that
/// will stay. The user needs to see them before agreeing to the move.
- static func whatStays(_ plan: UninstallPlan, app: InstalledApp, homebrew: CaskLookup.Answer, scan: LeftoverScan) -> [String] {
+ static func whatStays(
+ _ plan: UninstallPlan,
+ app: InstalledApp,
+ homebrew: CaskLookup.Answer,
+ scan: LeftoverScan
+ ) -> [String] {
var notes: [String] = []
if let note = homebrew.note {
notes.append(note)
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
index 8a05a7b6..ebb6afe6 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/FileCommands.swift
@@ -72,10 +72,21 @@ struct OrphansCommand: AsyncParsableCommand {
let exclusions = await UnreadableExclusions.load()
let scanner = OrphanScanner(exclusions: exclusions)
let scan = await ProgressLine.counting {
- await scanner.scan(installedApps: apps, remembered: remembered, running: running, owners: OrphanOwners().load())
+ await scanner.scan(
+ installedApps: apps,
+ remembered: remembered,
+ running: running,
+ owners: OrphanOwners().load()
+ )
}
if let group {
- return try await clean(group, in: scan, apps: apps, scanner: scanner, using: TrashService(exclusions: exclusions))
+ return try await clean(
+ group,
+ in: scan,
+ apps: apps,
+ scanner: scanner,
+ using: TrashService(exclusions: exclusions)
+ )
}
if output.json {
@@ -248,7 +259,10 @@ struct CachesCommand: AsyncParsableCommand {
/// Returns the environments named in `tools`, by the name the listing shows or by its identifier, ignoring
/// case. All of them when `tools` is empty. A name that matches none fails the command, even beside one that
/// matches: shown the rest, a typo would read as a tool with nothing to show.
- static func chosen(from environments: [DeveloperEnvironment], named tools: [String]) throws -> [DeveloperEnvironment] {
+ static func chosen(
+ from environments: [DeveloperEnvironment],
+ named tools: [String]
+ ) throws -> [DeveloperEnvironment] {
guard !tools.isEmpty else { return environments }
func isNamed(_ environment: DeveloperEnvironment, _ tool: String) -> Bool {
[environment.name, environment.id].contains { tool.caseInsensitiveCompare($0) == .orderedSame }
@@ -567,7 +581,9 @@ struct DuplicatesCommand: AsyncParsableCommand {
Output.line(Self.heading(for: group))
Output.table(Self.rows(for: group.files.map(\.url)), indent: " ")
}
- let total = scan.groups.reduce(0) { $0 + $1.reclaimableSize } + scan.folderGroups.reduce(0) { $0 + $1.reclaimableSize }
+ let total =
+ scan.groups.reduce(0) { $0 + $1.reclaimableSize }
+ + scan.folderGroups.reduce(0) { $0 + $1.reclaimableSize }
Output.line("Total to free: \(Output.size(total))")
}
Self.notes(for: scan).forEach(Output.note)
@@ -599,7 +615,9 @@ struct DuplicatesCommand: AsyncParsableCommand {
folders: group.folders.map { Output.path($0.url) }
)
},
- files: scan.groups.map { Record(size: $0.size, reclaimableSize: $0.reclaimableSize, files: $0.files.map { Output.path($0.url) }) },
+ files: scan.groups.map {
+ Record(size: $0.size, reclaimableSize: $0.reclaimableSize, files: $0.files.map { Output.path($0.url) })
+ },
unreadableLocations: scan.unreadableLocations.map(Output.path),
skippedLocations: scan.skippedLocations.map(Output.path)
)
@@ -646,7 +664,8 @@ struct DuplicatesCommand: AsyncParsableCommand {
+ scan.groups.compactMap { $0.files.first?.url }
Output.table(kept.map { ["keep", Output.path($0)] })
let cleanup = Cleanup.of(
- folders.map { (url: $0.url, size: $0.reclaimableSize) } + files.map { (url: $0.url, size: $0.reclaimableSize) },
+ folders.map { (url: $0.url, size: $0.reclaimableSize) }
+ + files.map { (url: $0.url, size: $0.reclaimableSize) },
source: "Duplicates",
sourceKey: "tool",
tool: "duplicates",
@@ -723,11 +742,17 @@ struct SearchCommand: AsyncParsableCommand {
}
if output.json {
- try Output.json(results.files.map { Record(path: Output.path($0.url), size: $0.size, modificationDate: $0.modificationDate) })
+ try Output.json(
+ results.files.map {
+ Record(path: Output.path($0.url), size: $0.size, modificationDate: $0.modificationDate)
+ }
+ )
} else if results.files.isEmpty {
Output.line("No files found.")
} else {
- Output.table(results.files.map { [Output.size($0.size), Output.day($0.modificationDate), Output.path($0.url)] })
+ Output.table(
+ results.files.map { [Output.size($0.size), Output.day($0.modificationDate), Output.path($0.url)] }
+ )
}
if results.isTruncated {
Output.note("Only the first \(Output.number(FileSearch.maximumResults)) files are shown. Narrow the search to see the rest.")
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
index 7693f0de..52d5358a 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Commands/HistoryCommands.swift
@@ -176,7 +176,9 @@ struct HistoryCommand: AsyncParsableCommand {
size: MeasuredSize(batch.size),
itemCount: batch.records.count,
restorableCount: batch.restorable.count,
- files: batch.records.map { FileRecord(path: Output.path($0.originalURL), size: MeasuredSize($0.size)) }
+ files: batch.records.map {
+ FileRecord(path: Output.path($0.originalURL), size: MeasuredSize($0.size))
+ }
)
})
} else if batches.isEmpty {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
index 2f818b77..f544ee86 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/AppLookup.swift
@@ -27,7 +27,11 @@ enum AppLookup {
/// Throws when `app` is excluded in Peel's settings, so the command line leaves it alone as the app does.
/// While the saved list can't be read, it throws for every app, since what the user excluded is unknown.
- static func refuseIfExcluded(_ app: InstalledApp, by exclusions: Exclusions, savedAt url: URL = ExclusionStore.defaultURL) throws(Failure) {
+ static func refuseIfExcluded(
+ _ app: InstalledApp,
+ by exclusions: Exclusions,
+ savedAt url: URL = ExclusionStore.defaultURL
+ ) throws(Failure) {
guard !exclusions.isUnreadable else { throw .exclusionsUnreadable(url.path(percentEncoded: false)) }
guard exclusions.excludes(app) else { return }
throw .excluded(app.name)
@@ -56,7 +60,11 @@ enum AppLookup {
default: throw .ambiguous(query, byIdentifier.map { normalizedPath($0.url) })
}
// Compared without the user's locale: under Turkish rules, `iina` wouldn't match `IINA`.
- let named = apps.filter { names(of: $0).contains { $0.compare(bareName(query), options: [.caseInsensitive, .widthInsensitive]) == .orderedSame } }
+ let named = apps.filter {
+ names(of: $0).contains {
+ $0.compare(bareName(query), options: [.caseInsensitive, .widthInsensitive]) == .orderedSame
+ }
+ }
let local = localBundle(named: query, in: folder).map(normalizedPath)
let paths = named.map { normalizedPath($0.url) }
if let local, !paths.isEmpty, !paths.contains(local) {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Arguments.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Arguments.swift
index da499ed2..19d486a1 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Arguments.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Arguments.swift
@@ -105,7 +105,9 @@ struct ByteSize: ExpressibleByArgument, Equatable {
let text = argument.trimmingCharacters(in: .whitespaces).uppercased()
let unit = Self.units.first { text.hasSuffix($0.suffix) }
let number = unit.map { String(text.dropLast($0.suffix.count)) } ?? text
- guard let value = Double(number.trimmingCharacters(in: .whitespaces)), value.isFinite, value >= 0 else { return nil }
+ guard let value = Double(number.trimmingCharacters(in: .whitespaces)), value.isFinite, value >= 0 else {
+ return nil
+ }
let bytes = (value * (unit?.multiplier ?? 1)).rounded()
guard bytes < Double(Int64.max) else { return nil }
self.bytes = Int64(bytes)
@@ -115,7 +117,8 @@ struct ByteSize: ExpressibleByArgument, Equatable {
/// Returns whether `url` is an existing folder, so a wrong path gets an error rather than an empty result.
func isAFolder(_ url: URL) -> Bool {
var isDirectory: ObjCBool = false
- return FileManager.default.fileExists(atPath: url.path(percentEncoded: false), isDirectory: &isDirectory) && isDirectory.boolValue
+ return FileManager.default.fileExists(atPath: url.path(percentEncoded: false), isDirectory: &isDirectory)
+ && isDirectory.boolValue
}
extension URL {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/CaskLookup.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/CaskLookup.swift
index dbaaca6b..6e6565f5 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/CaskLookup.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/CaskLookup.swift
@@ -25,9 +25,16 @@ enum CaskLookup {
async let installed = Homebrew.installedPackages()
let known = await CaskEvidence.knownCasks(for: [app], receipts: receipts)
do {
- return Answer(casks: CaskEvidence.combined(installed: try await installed, known: known, receipts: receipts), receipts: receipts)
+ return Answer(
+ casks: CaskEvidence.combined(installed: try await installed, known: known, receipts: receipts),
+ receipts: receipts
+ )
} catch {
- return Answer(casks: CaskEvidence.combined(installed: [], known: known, receipts: receipts), receipts: receipts, failure: why(error))
+ return Answer(
+ casks: CaskEvidence.combined(installed: [], known: known, receipts: receipts),
+ receipts: receipts,
+ failure: why(error)
+ )
}
}
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/ProgressLine.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/ProgressLine.swift
index a981ea40..f86b542f 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/ProgressLine.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/ProgressLine.swift
@@ -12,7 +12,10 @@ enum ProgressLine {
private static let redraw = DispatchTimeInterval.milliseconds(100)
/// Runs a scan that counts what it reads (`ScanCount`), and shows how much it has read.
- static func counting<Answer>(on descriptor: Int32 = STDERR_FILENO, _ scan: () async throws -> Answer) async rethrows -> Answer {
+ static func counting<Answer>(
+ on descriptor: Int32 = STDERR_FILENO,
+ _ scan: () async throws -> Answer
+ ) async rethrows -> Answer {
let count = ScanCount()
return try await showing({ lookedAt(count.value) }, on: descriptor) {
try await ScanCount.$current.withValue(count) { try await scan() }
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
index 0fbfc146..4280be6a 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/UninstallPlan.swift
@@ -39,7 +39,10 @@ struct UninstallPlan {
let app = uninstallation.app.url
let selection = keepLeftovers ? [app] : uninstallation.suggestedSelection(canUseHelper: false)
let ordered = [app] + uninstallation.removalOrder(of: selection).filter { $0 != app }
- let leftovers = Dictionary(uninstallation.scan.leftovers.map { ($0.url, $0) }, uniquingKeysWith: { first, _ in first })
+ let leftovers = Dictionary(
+ uninstallation.scan.leftovers.map { ($0.url, $0) },
+ uniquingKeysWith: { first, _ in first }
+ )
let items = ordered.filter(selection.contains).map { url in
let leftover = leftovers[url]
diff --git a/Packages/PeelCore/Sources/PeelLink/OpenRequest.swift b/Packages/PeelCore/Sources/PeelLink/OpenRequest.swift
index b22537c6..e90bb8c3 100644
--- a/Packages/PeelCore/Sources/PeelLink/OpenRequest.swift
+++ b/Packages/PeelCore/Sources/PeelLink/OpenRequest.swift
@@ -28,7 +28,8 @@ public enum OpenRequest {
guard
url.scheme?.lowercased() == "peel",
url.host()?.lowercased() == "open",
- let path = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?.first(where: { $0.name == "path" })?.value,
+ let path = URLComponents(url: url, resolvingAgainstBaseURL: false)?.queryItems?
+ .first(where: { $0.name == "path" })?.value,
path.hasPrefix("/"),
!path.unicodeScalars.contains(where: { $0.properties.generalCategory == .control })
else { return nil }