use crate::{
create_file,
modules::updateable::{load_content, ProgramInfo, ShellInformation},
utils::proc::ProcessMan,
};
use std::collections::HashMap;
use std::sync::LazyLock;
pub struct ShellConfig {
pub alias_file: String,
pub config_file: String,
}
pub static SHELLS_REMOTE: LazyLock<ProgramInfo> = LazyLock::new(load_content);
pub static SHELLS_INFO: LazyLock<HashMap<String, &ShellInformation>> = LazyLock::new(|| {
let mut m: HashMap<String, &ShellInformation> = HashMap::new();
let arr = &*SHELLS_REMOTE.shells;
for info in arr {
m.insert((*info.name).to_string(), info);
}
m
});
pub fn get_shell() -> String {
let pm = ProcessMan::new();
pm.get_parent_name()
}
pub fn home() -> String {
std::env::var("HOME").expect("We required the $HOME env variable")
}
pub fn get_info(name: &str) -> [String; 2] {
let homedir = home();
let cfg = (*SHELLS_INFO)
.get(name)
.expect("Shell configuration file not found!");
let cfg_file = format!("{homedir}/{}", cfg.config);
create_file(cfg_file.as_str()).expect("Unable to create/found config file for terminal");
let alias_file = format!("{homedir}/{}", cfg.alias);
create_file(alias_file.as_str()).expect("Unable to create/found config file for terminal");
[cfg_file, alias_file]
}