Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
eugenesvk committed Dec 4, 2024
1 parent 175d6f5 commit e499a0e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,17 @@ fn delete_using_finder<P: AsRef<Path>>(full_paths: &[P]) -> Result<(), Error> {
// osascript -e 'tell application "Finder" to delete { POSIX file "file1", POSIX "file2" }'
// The `-e` flag is used to execute only one line of AppleScript.
let mut command = Command::new("osascript");
let posix_files = full_paths.into_iter().map(|p| {
let path_b = p.as_ref().as_os_str().as_encoded_bytes();
match simdutf8::basic::from_utf8(path_b) {
Ok(path_utf8) => format!("POSIX file \"{path_utf8}\""), // utf-8 path, use as is
Err(_) => format!("POSIX file \"{}\"",&from_utf8_lossy_pc(path_b)), // binary path, %-encode it
}
}).collect::<Vec<String>>().join(", ");
let posix_files = full_paths
.into_iter()
.map(|p| {
let path_b = p.as_ref().as_os_str().as_encoded_bytes();
match simdutf8::basic::from_utf8(path_b) {
Ok(path_utf8) => format!("POSIX file \"{path_utf8}\""), // utf-8 path, use as is
Err(_) => format!("POSIX file \"{}\"", &from_utf8_lossy_pc(path_b)), // binary path, %-encode it
}
})
.collect::<Vec<String>>()
.join(", ");
let script = format!("tell application \"Finder\" to delete {{ {posix_files} }}");

let argv: Vec<OsString> = vec!["-e".into(), script.into()];
Expand Down

0 comments on commit e499a0e

Please sign in to comment.