use std::path::Path; use std::path::PathBuf; use dirs::home_dir; use shlex::try_join; pub(crate) fn escape_command(command: &[String]) -> String { try_join(command.iter().map(std::string::String::as_str)).unwrap_or_else(|_| command.join(" ")) } pub(crate) fn strip_bash_lc_and_escape(command: &[String]) -> String { match command { [first, second, third] if first == "bash" && second == "-lc" => third.clone(), _ => escape_command(command), } } /// If `path` is absolute and inside $HOME, return the part *after* the home /// directory; otherwise, return the path as-is. Note if `path` is the homedir, /// this will return and empty path. pub(crate) fn relativize_to_home
(path: P) -> Option