
These files cannot be trashed from CLI without sudo, which trashes them instead to root's Trash. AppleScript isn't of use here because it will break Travis (as it will fail when asking for admin permissions). Fixes homebrew/homebrew-cask#69897
29 lines
566 B
Swift
29 lines
566 B
Swift
#!/usr/bin/swift
|
|
|
|
import Foundation
|
|
|
|
struct swifterr: TextOutputStream {
|
|
public static var stream = swifterr()
|
|
mutating func write(_ string: String) { fputs(string, stderr) }
|
|
}
|
|
|
|
if (CommandLine.arguments.count < 2) {
|
|
exit(2)
|
|
}
|
|
|
|
let manager: FileManager = FileManager()
|
|
|
|
for item in CommandLine.arguments[1...] {
|
|
do {
|
|
let path: URL = URL(fileURLWithPath: item)
|
|
try manager.trashItem(at: path, resultingItemURL: nil)
|
|
print(path, terminator: "\0")
|
|
}
|
|
catch {
|
|
print(error.localizedDescription, to: &swifterr.stream)
|
|
exit(1)
|
|
}
|
|
}
|
|
|
|
exit(0)
|