2024-11-21 10:58:26 +00:00
|
|
|
mod indicators {
|
2024-11-25 07:53:37 +00:00
|
|
|
pub mod error;
|
2024-11-24 14:23:15 +00:00
|
|
|
pub mod git;
|
2024-11-26 08:13:39 +00:00
|
|
|
pub mod pwd;
|
2024-11-24 14:23:15 +00:00
|
|
|
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;
|
2024-11-24 14:23:15 +00:00
|
|
|
use crate::indicators::ssh;
|
2024-11-23 11:20:15 +00:00
|
|
|
use crate::indicators::user;
|
2024-11-28 10:51:38 +00:00
|
|
|
use ansi_term::{ANSIGenericString, ANSIGenericStrings};
|
2024-08-14 14:58:16 +00:00
|
|
|
|
2024-11-24 14:23:15 +00:00
|
|
|
fn main() {
|
2024-11-28 10:51:38 +00:00
|
|
|
let cmd_args: Vec<String> = std::env::args().collect(); // Cmd-line args
|
2024-11-27 11:11:55 +00:00
|
|
|
|
2024-11-28 10:51:38 +00:00
|
|
|
let mut components: Vec<ANSIGenericString<'static, str>> = Vec::new(); // The components will be concated into one string
|
2024-11-23 11:20:15 +00:00
|
|
|
|
2024-11-24 14:23: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;
|
2024-11-24 14:23:15 +00:00
|
|
|
let indicate_git_branch: bool = true;
|
2024-11-27 11:11:55 +00:00
|
|
|
let show_pwd: bool = true;
|
|
|
|
let abbrev_home: bool = true;
|
|
|
|
let shorten_path: bool = true;
|
|
|
|
let replace_repo: bool = true;
|
2024-11-28 10:51:38 +00:00
|
|
|
|
|
|
|
let git_info: Option<(String, String)> = if indicate_git_branch || replace_repo {
|
|
|
|
git::info()
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
2024-11-24 14:23:15 +00:00
|
|
|
|
2024-11-25 07:53:37 +00:00
|
|
|
if indicate_ssh {
|
2024-11-28 10:51:38 +00:00
|
|
|
components.push(ssh::indicator());
|
2024-11-25 07:53:37 +00:00
|
|
|
}
|
2024-11-24 14:23:15 +00:00
|
|
|
if indicate_git_branch {
|
|
|
|
match git_info {
|
2024-11-28 10:51:38 +00:00
|
|
|
Some(ref info) => components.push(git::indicator(Some(info.1.clone()))),
|
|
|
|
None => components.push(git::indicator(None)),
|
2024-11-27 11:11:55 +00:00
|
|
|
}
|
2024-11-24 14:23:15 +00:00
|
|
|
}
|
2024-11-23 11:20:15 +00:00
|
|
|
if indicate_user {
|
2024-11-28 10:51:38 +00:00
|
|
|
components.push(user::indicator());
|
2024-11-23 11:20:15 +00:00
|
|
|
}
|
2024-11-25 07:53:37 +00:00
|
|
|
if indicate_err {
|
2024-11-29 06:40:02 +00:00
|
|
|
components.push(error::indicator(&cmd_args));
|
2024-11-27 11:11:55 +00:00
|
|
|
}
|
|
|
|
if show_pwd {
|
|
|
|
let repo_path = match git_info {
|
2024-11-28 11:13:58 +00:00
|
|
|
Some(info) => Some(info.0),
|
2024-11-27 11:11:55 +00:00
|
|
|
None => None,
|
|
|
|
};
|
|
|
|
components.insert(
|
|
|
|
0,
|
2024-11-28 10:51:38 +00:00
|
|
|
pwd::pwd(abbrev_home, shorten_path, replace_repo, repo_path),
|
2024-11-27 11:11:55 +00:00
|
|
|
);
|
2024-11-25 07:53:37 +00:00
|
|
|
}
|
2024-11-28 10:51:38 +00:00
|
|
|
let prompt: ANSIGenericStrings<'_, str> = ANSIGenericStrings(&components[..]);
|
2024-11-24 14:23:15 +00:00
|
|
|
print!("{prompt} ");
|
2024-08-19 13:24:12 +00:00
|
|
|
}
|