Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
24 changes: 17 additions & 7 deletions src/bin/ssh-agent-mux/cli.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -81,16 +86,21 @@ impl Config {
Config::from(&mut args.config)
};

fn expand_path(p: &Path) -> EyreResult<PathBuf> {
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::<Result<_, _>>()?;

Ok(config)
Expand Down
2 changes: 1 addition & 1 deletion src/bin/ssh-agent-mux/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down