PrettyPrompt/src/main.rs

59 lines
1.6 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();
let mut components: Vec<String> = Vec::new();
2024-11-23 11:20:15 +00:00
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;
let show_pwd: bool = true;
let abbrev_home: bool = true;
let shorten_path: bool = true;
let replace_repo: bool = true;
let mut git_info = None;
2024-11-25 07:53:37 +00:00
if indicate_ssh {
components.push(ssh::indicator().to_string());
2024-11-25 07:53:37 +00:00
}
if indicate_git_branch {
git_info = git::info();
match git_info {
Some(ref info) => components.push(git::indicator(Some(info.1.clone())).to_string()),
None => components.push(git::indicator(None).to_string()),
}
}
2024-11-23 11:20:15 +00:00
if indicate_user {
components.push(user::indicator().to_string());
2024-11-23 11:20:15 +00:00
}
2024-11-25 07:53:37 +00:00
if indicate_err {
components.push(error::indicator(cmd_args).to_string());
}
if show_pwd {
let repo_path = match git_info {
Some(info) => Some(info.0), // Clone to avoid ownership issues
None => None,
};
components.insert(
0,
pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path).to_string(),
);
2024-11-25 07:53:37 +00:00
}
let prompt = components.join("");
print!("{prompt} ");
2024-08-19 13:24:12 +00:00
}