feat: Add percent-encoding dependency and enhance path handling in main.rs
This commit is contained in:
parent
e978c542df
commit
de5c0ab4a9
3 changed files with 20 additions and 1 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
13
src/main.rs
13
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(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue