diff --git a/Cargo.lock b/Cargo.lock index 75950fd..a858567 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1377,6 +1377,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7a6f98357c6bb0ebace19b22220e5543801d9de90ffe77f8abb27c056bac064" +[[package]] +name = "shellexpand" +version = "3.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b1fdf65dd6331831494dd616b30351c38e96e45921a27745cf98490458b90bb" +dependencies = [ + "dirs", +] + [[package]] name = "shlex" version = "1.3.0" @@ -1476,6 +1485,7 @@ dependencies = [ "log", "serde", "service-manager", + "shellexpand", "ssh-agent-lib", "tempfile", "tokio", diff --git a/Cargo.toml b/Cargo.toml index e9acd98..48651d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ expand-tilde = "0.6.0" flexi_logger = "0.30.1" ssh-agent-lib = "0.5.1" toml = "0.8.22" +shellexpand = "3.1.1" [dependencies.color-eyre] version = "0.6.3" diff --git a/src/bin/ssh-agent-mux/cli.rs b/src/bin/ssh-agent-mux/cli.rs index 6c7cad5..a076552 100644 --- a/src/bin/ssh-agent-mux/cli.rs +++ b/src/bin/ssh-agent-mux/cli.rs @@ -1,11 +1,16 @@ -use std::{env, fs::File, io::Read, path::PathBuf}; +use std::{ + env, + fs::File, + io::Read, + path::{Path, PathBuf}, +}; use clap_serde_derive::{ clap::{self, Parser, ValueEnum}, serde::{self, Deserialize, Serialize}, ClapSerde, }; -use color_eyre::eyre::Result as EyreResult; +use color_eyre::eyre::{eyre, Result as EyreResult}; use expand_tilde::ExpandTilde; use log::LevelFilter; @@ -81,16 +86,21 @@ impl Config { Config::from(&mut args.config) }; + fn expand_path(p: &Path) -> EyreResult { + let p = p + .to_str() + .ok_or_else(|| eyre!("failed to convert {} to str", p.display()))?; + let expanded = shellexpand::full(p)?; + Ok(PathBuf::from(&expanded as &str)) + } + config.config_path = args.config_path; config.listen_path = config.listen_path.expand_tilde_owned()?; - config.log_file = config - .log_file - .map(|p| p.expand_tilde_owned()) - .transpose()?; + config.log_file = config.log_file.map(|p| expand_path(&p)).transpose()?; config.agent_sock_paths = config .agent_sock_paths .into_iter() - .map(|p| p.expand_tilde_owned()) + .map(|p| expand_path(&p)) .collect::>()?; Ok(config) diff --git a/src/bin/ssh-agent-mux/service.rs b/src/bin/ssh-agent-mux/service.rs index ce92afa..d2b97a3 100644 --- a/src/bin/ssh-agent-mux/service.rs +++ b/src/bin/ssh-agent-mux/service.rs @@ -122,7 +122,7 @@ fn write_new_config_file(config: &Config) -> Result<()> { if config.agent_sock_paths.is_empty() { match env::var("SSH_AUTH_SOCK") { Ok(v) => { - success_msg.write_str("with the current SSH_AUTh_SOCK as the upstream agent; please edit to add additional agents.")?; + success_msg.write_str("with the current SSH_AUTH_SOCK as the upstream agent; please edit to add additional agents.")?; new_config.agent_sock_paths.push(v.into()); } Err(e) => {