From de5c0ab4a9c4c7cb07fbd8f1bec659160ab17b8d Mon Sep 17 00:00:00 2001 From: monoid Date: Wed, 9 Jul 2025 00:09:45 +0900 Subject: [PATCH] feat: Add percent-encoding dependency and enhance path handling in main.rs --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/main.rs | 13 ++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index a5bb422..697f0e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -154,6 +154,7 @@ version = "0.1.0" dependencies = [ "clap", "dirs", + "percent-encoding", "serde", "serde_json", "shellexpand", @@ -206,6 +207,12 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "proc-macro2" version = "1.0.95" diff --git a/Cargo.toml b/Cargo.toml index a7e42ba..fab229d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2024" [dependencies] clap = { version = "4.5.4", features = ["derive"] } dirs = "5.0.1" +percent-encoding = "2.3.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" shellexpand = "3.1.0" diff --git a/src/main.rs b/src/main.rs index 20b9726..7e0dc72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ use clap::{Parser, Subcommand}; use std::path::PathBuf; use std::process::Command; +use percent_encoding; mod platform; mod config; @@ -50,9 +51,15 @@ fn handle_open(path: &str) -> Result<(), String> { explorer: None, base_path: None, }); + println!("Opening path: {}", path); let path_without_scheme = path.strip_prefix("ionian-find:").unwrap_or(path); let relative_path = path_without_scheme.trim_start_matches('/'); + // decode percent-encoded characters + let relative_path = percent_encoding::percent_decode_str(relative_path) + .decode_utf8() + .map_err(|e| format!("Failed to decode path: {}", e))? + .to_string(); let mut full_path = PathBuf::new(); if let Some(base_path) = &config.base_path { @@ -60,6 +67,8 @@ fn handle_open(path: &str) -> Result<(), String> { } full_path.push(relative_path); + println!("Opening the file explorer to: {:?}", full_path); + let result = full_path.canonicalize() .expect("Failed to canonicalize path") .to_str() @@ -70,10 +79,12 @@ fn handle_open(path: &str) -> Result<(), String> { let explorer = config.explorer.unwrap_or_else(|| "xdg-open".to_string()); Command::new(explorer) - .arg(result) + .args([result]) .output() .map_err(|e| format!("Failed to execute file explorer: {}", e))?; + // PAUSE the program to allow the user to see the output + Ok(()) }