pub mod capability;
pub mod config_gen;
pub mod settings;
pub mod templates;
pub mod tui;
pub mod zshrc;
use settings::WizardSettings;
pub fn run(force: bool) -> i32 {
let Some(root) = crate::p10k::p10k_root_dir() else {
eprintln!(
"zshrs: p10k: configure: powerlevel10k install root unknown \
(source the theme first)"
);
return 1;
};
match tui::run_wizard(&root, force) {
Ok(Some(outcome)) => {
if let Err(e) = commit(&root, &outcome) {
eprintln!("zshrs: p10k: configure: {e}");
return 1;
}
0
}
Ok(None) => 1,
Err(e) => {
eprintln!("zshrs: p10k: configure: {e}");
1
}
}
}
pub struct Outcome {
pub settings: WizardSettings,
pub config_path: String,
pub write_zshrc: bool,
pub zshrc_path: String,
pub timestamp: String,
}
fn commit(root: &str, o: &Outcome) -> std::io::Result<()> {
let base_path = format!(
"{root}/config/p10k-{}.zsh",
o.settings.style.template_name()
);
let base = std::fs::read_to_string(&base_path).map_err(|e| {
std::io::Error::new(
e.kind(),
format!("cannot read base template {base_path}: {e}"),
)
})?;
let text = config_gen::generate_config(&base, &o.settings, &o.timestamp);
if let Some(dir) = std::path::Path::new(&o.config_path).parent() {
std::fs::create_dir_all(dir)?;
}
std::fs::write(&o.config_path, text)?;
if o.write_zshrc {
zshrc::change_zshrc(&o.zshrc_path, &o.config_path)?; }
Ok(())
}