mirror of
https://github.com/veeso/termscp.git
synced 2026-04-05 09:41:53 -07:00
feat: Import bookmarks from ssh config with a CLI command (#364)
* feat: Import bookmarks from ssh config with a CLI command Use import-ssh-hosts to import all the possible hosts by the configured ssh config or the default one on your machine closes #331
This commit is contained in:
committed by
GitHub
parent
4bebec369f
commit
f4156a5059
@@ -99,27 +99,14 @@ impl SetupActivity {
|
||||
Ok(State::One(StateValue::Usize(idx))) => Some(idx),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(idx) = idx {
|
||||
let key: Option<String> = self.config().iter_ssh_keys().nth(idx).cloned();
|
||||
if let Some(key) = key {
|
||||
match self.config().get_ssh_key(&key) {
|
||||
Ok(opt) => {
|
||||
if let Some((host, username, _)) = opt {
|
||||
if let Err(err) = self.delete_ssh_key(host.as_str(), username.as_str())
|
||||
{
|
||||
// Report error
|
||||
self.mount_error(err.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
// Report error
|
||||
self.mount_error(
|
||||
format!("Could not get ssh key \"{key}\": {err}").as_str(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
// get ssh key and delete it
|
||||
if let Some(Err(err)) = idx
|
||||
.and_then(|i| self.config().iter_ssh_keys().nth(i).cloned())
|
||||
.and_then(|key| self.config().get_ssh_key(&key))
|
||||
.map(|(host, username, _)| self.delete_ssh_key(host.as_str(), username.as_str()))
|
||||
{
|
||||
// Report error
|
||||
self.mount_error(err.as_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,16 +77,11 @@ impl SetupActivity {
|
||||
Some(key) => {
|
||||
// Get key path
|
||||
match ctx.config().get_ssh_key(key) {
|
||||
Ok(ssh_key) => match ssh_key {
|
||||
None => Ok(()),
|
||||
Some((_, _, key_path)) => {
|
||||
match edit::edit_file(key_path.as_path()) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(format!("Could not edit ssh key: {err}")),
|
||||
}
|
||||
}
|
||||
None => Ok(()),
|
||||
Some((_, _, key_path)) => match edit::edit_file(key_path.as_path()) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(err) => Err(format!("Could not edit ssh key: {err}")),
|
||||
},
|
||||
Err(err) => Err(format!("Could not read ssh key: {err}")),
|
||||
}
|
||||
}
|
||||
None => Ok(()),
|
||||
|
||||
@@ -126,7 +126,7 @@ impl SetupActivity {
|
||||
.config()
|
||||
.iter_ssh_keys()
|
||||
.map(|x| {
|
||||
let (addr, username, _) = self.config().get_ssh_key(x).ok().unwrap().unwrap();
|
||||
let (addr, username, _) = self.config().get_ssh_key(x).unwrap();
|
||||
format!("{username} at {addr}")
|
||||
})
|
||||
.collect();
|
||||
|
||||
Reference in New Issue
Block a user