diff options
| author | Markus Reiter | 2017-06-16 16:14:17 +0200 |
|---|---|---|
| committer | Markus Reiter | 2017-06-20 15:53:33 +0200 |
| commit | fc739bf82e263b54dca30713388f3ffd712aba6a (patch) | |
| tree | bd53c2f15268ede54fa780f8efc4d348bfbc3069 /Library/Homebrew/utils | |
| parent | 80ce43dff1a196d021f64277a2d3b6aa3e2898f7 (diff) | |
| download | brew-fc739bf82e263b54dca30713388f3ffd712aba6a.tar.bz2 | |
Add `trash` util.
Diffstat (limited to 'Library/Homebrew/utils')
| -rwxr-xr-x | Library/Homebrew/utils/trash.swift | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Library/Homebrew/utils/trash.swift b/Library/Homebrew/utils/trash.swift new file mode 100755 index 000000000..f591c3806 --- /dev/null +++ b/Library/Homebrew/utils/trash.swift @@ -0,0 +1,43 @@ +#!/usr/bin/swift + +import Cocoa + +DispatchQueue.main.async { + let arguments = CommandLine.arguments.dropFirst().filter { !$0.isEmpty } + let URLs = arguments.map { URL(fileURLWithPath: $0) } + + #if swift(>=4.0) + let workspace = NSWorkspace.shared + #else + let workspace = NSWorkspace.shared() + #endif + + workspace.recycle(URLs) { (dict, error) in + dict.forEach { + #if swift(>=4.0) + let originalPath = $0.0.path + let trashPath = $0.1.path + #else + let originalPath = $0.path + let trashPath = $1.path + #endif + + print("moved \(originalPath) to \(trashPath)") + } + + if error == nil { + exit(0) + } + + let trashedURLs = dict.keys + let untrashedURLs = URLs.filter { !trashedURLs.contains($0) } + + untrashedURLs.forEach { + fputs("could not move \($0.path) to trash\n", stderr) + } + + exit(1) + } +} + +RunLoop.main.run() |
