mod indicators { pub mod error; pub mod git; pub mod pwd; pub mod ssh; pub mod user; } use crate::indicators::error; use crate::indicators::git; use crate::indicators::pwd; use crate::indicators::ssh; use crate::indicators::user; use ansi_term::{ANSIGenericString, ANSIGenericStrings}; fn main() { let cmd_args: Vec = std::env::args().collect(); // Cmd-line args let mut components: Vec> = Vec::new(); // The components will be concated into one string // Hard-coded configuration. This will be replaced by a configuration file in a future version let indicate_user: bool = true; let indicate_ssh: bool = true; let indicate_err: bool = true; let indicate_git_branch: bool = true; let show_pwd: bool = true; let abbrev_home: bool = true; let shorten_path: bool = true; let replace_repo: bool = true; let git_info: Option<(String, String)> = if indicate_git_branch || replace_repo { git::info() } else { None }; // Conditionally add the parts of the prompt if indicate_ssh { components.push(ssh::indicator()); } if indicate_git_branch { match git_info { Some(ref info) => components.push(git::indicator(Some(info.1.clone()))), None => components.push(git::indicator(None)), } } if indicate_user { components.push(user::indicator()); } if indicate_err { components.push(error::indicator(&cmd_args)); } if show_pwd { let repo_path = match git_info { Some(info) => Some(info.0), None => None, }; components.insert( 0, pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path), ); } let prompt: ANSIGenericStrings<'_, str> = ANSIGenericStrings(&components[..]); print!("{prompt} "); }