PrettyPrompt/src/main.rs

47 lines
1.2 KiB
Rust
Raw Normal View History

2024-11-21 10:58:26 +00:00
mod indicators {
2024-11-25 07:53:37 +00:00
pub mod error;
pub mod git;
2024-11-26 08:13:39 +00:00
pub mod pwd;
pub mod ssh;
2024-11-21 10:58:26 +00:00
pub mod user;
2024-08-14 14:58:16 +00:00
}
2024-11-26 07:04:31 +00:00
2024-11-25 07:53:37 +00:00
use crate::indicators::error;
use crate::indicators::git;
2024-11-26 08:13:39 +00:00
use crate::indicators::pwd;
use crate::indicators::ssh;
2024-11-23 11:20:15 +00:00
use crate::indicators::user;
2024-08-14 14:58:16 +00:00
fn main() {
2024-11-25 07:53:37 +00:00
let cmd_args: Vec<String> = std::env::args().collect();
2024-11-23 11:20:15 +00:00
let mut prompt: String = String::new();
let indicate_user: bool = true;
let indicate_ssh: bool = true;
2024-11-25 07:53:37 +00:00
let indicate_err: bool = true;
let indicate_git_branch: bool = true;
2024-11-26 07:04:31 +00:00
let pwd: bool = true;
2024-11-26 08:13:39 +00:00
let abbrev_home:bool = true;
2024-11-26 07:04:31 +00:00
if pwd {
2024-11-26 08:13:39 +00:00
prompt += &pwd::pwd(abbrev_home).to_string();
2024-11-26 07:04:31 +00:00
}
2024-11-25 07:53:37 +00:00
if indicate_ssh {
prompt += &ssh::indicator().to_string();
}
if indicate_git_branch {
let git_info = git::info();
match git_info {
Some((_repo, branch)) => prompt += &git::indicator(Some(branch)).to_string(),
None => prompt += &git::indicator(None).to_string(),
};
}
2024-11-23 11:20:15 +00:00
if indicate_user {
prompt += &user::indicator().to_string();
}
2024-11-25 07:53:37 +00:00
if indicate_err {
prompt += &error::indicator(cmd_args).to_string();
}
print!("{prompt} ");
2024-08-19 13:24:12 +00:00
}