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 = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
"percent-encoding",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"shellexpand",
|
"shellexpand",
|
||||||
|
@ -206,6 +207,12 @@ version = "0.2.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "percent-encoding"
|
||||||
|
version = "2.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.95"
|
version = "1.0.95"
|
||||||
|
|
|
@ -6,6 +6,7 @@ edition = "2024"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.5.4", features = ["derive"] }
|
clap = { version = "4.5.4", features = ["derive"] }
|
||||||
dirs = "5.0.1"
|
dirs = "5.0.1"
|
||||||
|
percent-encoding = "2.3.1"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
shellexpand = "3.1.0"
|
shellexpand = "3.1.0"
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -1,6 +1,7 @@
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
use percent_encoding;
|
||||||
|
|
||||||
mod platform;
|
mod platform;
|
||||||
mod config;
|
mod config;
|
||||||
|
@ -50,9 +51,15 @@ fn handle_open(path: &str) -> Result<(), String> {
|
||||||
explorer: None,
|
explorer: None,
|
||||||
base_path: None,
|
base_path: None,
|
||||||
});
|
});
|
||||||
|
println!("Opening path: {}", path);
|
||||||
|
|
||||||
let path_without_scheme = path.strip_prefix("ionian-find:").unwrap_or(path);
|
let path_without_scheme = path.strip_prefix("ionian-find:").unwrap_or(path);
|
||||||
let relative_path = path_without_scheme.trim_start_matches('/');
|
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();
|
let mut full_path = PathBuf::new();
|
||||||
if let Some(base_path) = &config.base_path {
|
if let Some(base_path) = &config.base_path {
|
||||||
|
@ -60,6 +67,8 @@ fn handle_open(path: &str) -> Result<(), String> {
|
||||||
}
|
}
|
||||||
full_path.push(relative_path);
|
full_path.push(relative_path);
|
||||||
|
|
||||||
|
println!("Opening the file explorer to: {:?}", full_path);
|
||||||
|
|
||||||
let result = full_path.canonicalize()
|
let result = full_path.canonicalize()
|
||||||
.expect("Failed to canonicalize path")
|
.expect("Failed to canonicalize path")
|
||||||
.to_str()
|
.to_str()
|
||||||
|
@ -70,10 +79,12 @@ fn handle_open(path: &str) -> Result<(), String> {
|
||||||
let explorer = config.explorer.unwrap_or_else(|| "xdg-open".to_string());
|
let explorer = config.explorer.unwrap_or_else(|| "xdg-open".to_string());
|
||||||
|
|
||||||
Command::new(explorer)
|
Command::new(explorer)
|
||||||
.arg(result)
|
.args([result])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| format!("Failed to execute file explorer: {}", e))?;
|
.map_err(|e| format!("Failed to execute file explorer: {}", e))?;
|
||||||
|
|
||||||
|
// PAUSE the program to allow the user to see the output
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue