delete host config folder when deleting host definition

This commit is contained in:
0xf8 2023-05-30 00:22:21 -04:00
parent dc34e8e5f4
commit 73be0cbd4e
Signed by: 0xf8
GPG Key ID: 446580D758689584
2 changed files with 11 additions and 4 deletions

View File

@ -30,12 +30,12 @@ fn main() -> Result<()> {
let mut config: ConfigManager = ConfigManager::new(config_root, search_path)?;
let backend = TermionBackend::new(io::stdout().into_alternate_screen()?);
// let backend = TermionBackend::new(io::stdout()); // used for debugging
// let backend = TermionBackend::new(io::stdout().into_alternate_screen()?);
let backend = TermionBackend::new(io::stdout()); // used for debugging
let mut term = Terminal::new(backend)?;
loop {
term.clear()?;
// term.clear()?;
let mut host = input::get_host(&mut config)?;

View File

@ -1,6 +1,6 @@
use anyhow::Result;
use crate::{ ConfigManager, config::Host, input };
use dialoguer::{ Select, Input, Confirm, theme::ColorfulTheme };
use dialoguer::{ Select, Input, Confirm, Editor, theme::ColorfulTheme };
use serde::{ Serialize, Deserialize };
use ssh_key::PrivateKey;
use std::fs;
@ -166,6 +166,9 @@ Host {host}
}
1 => { // Edit config
// TODO: replace this with configuer::editor
// if let Some(cnf) = Editor::new().edit(fs::read_to_string(config.config_dir.join("config"))?.as_str())? {
// fs::write(config.config_dir.join("config"), cnf)?;
// }
let editor = std::env::var("EDITOR").expect("EDITOR is not set");
std::process::Command::new(editor)
.arg(host.config.to_owned())
@ -184,8 +187,12 @@ Host {host}
.interact()?;
if confirm {
let mut conf = std::path::PathBuf::from(host.config.to_owned());
conf.pop();
config.configs.remove(host);
config.save();
fs::remove_dir_all(conf)?;
break;
}
} // Back