From 0afe5fa24b8990991635c7023f0fb89403f55d90 Mon Sep 17 00:00:00 2001 From: sigoden Date: Wed, 10 Jul 2024 07:27:46 +0800 Subject: feat: `--file/.file` can load dirs (#693) --- src/utils/mod.rs | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) (limited to 'src/utils/mod.rs') diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 548c6f1..40967ab 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -2,6 +2,7 @@ mod abort_signal; mod clipboard; mod command; mod crypto; +mod path; mod prompt_input; mod render_prompt; mod request; @@ -11,6 +12,7 @@ pub use self::abort_signal::*; pub use self::clipboard::set_text; pub use self::command::*; pub use self::crypto::*; +pub use self::path::*; pub use self::prompt_input::*; pub use self::render_prompt::render_prompt; pub use self::request::*; @@ -20,10 +22,7 @@ use anyhow::{Context, Result}; use fancy_regex::Regex; use is_terminal::IsTerminal; use lazy_static::lazy_static; -use std::{ - env, - path::{self, Path, PathBuf}, -}; +use std::{env, path::PathBuf}; lazy_static! { pub static ref CODE_BLOCK_RE: Regex = Regex::new(r"(?ms)```\w*(.*)```").unwrap(); @@ -157,32 +156,6 @@ pub fn dimmed_text(input: &str) -> String { nu_ansi_term::Style::new().dimmed().paint(input).to_string() } -pub fn safe_join_path, T2: AsRef>( - base_path: T1, - sub_path: T2, -) -> Option { - let base_path = base_path.as_ref(); - let sub_path = sub_path.as_ref(); - if sub_path.is_absolute() { - return None; - } - - let mut joined_path = PathBuf::from(base_path); - - for component in sub_path.components() { - if path::Component::ParentDir == component { - return None; - } - joined_path.push(component); - } - - if joined_path.starts_with(base_path) { - Some(joined_path) - } else { - None - } -} - pub fn temp_file(prefix: &str, suffix: &str) -> PathBuf { env::temp_dir().join(format!( "{}{prefix}{}{suffix}", -- cgit v1.2.3