PrettyPrompt/src/main.rs

56 lines
1.4 KiB
Rust
Raw Normal View History

2024-11-21 10:58:26 +00:00
//use colored::{ColoredString, Colorize};
use colored::Colorize;
2024-08-19 13:24:12 +00:00
use std::env::{args, current_dir, var_os};
2024-08-14 14:58:16 +00:00
2024-11-21 10:58:26 +00:00
mod indicators {
pub mod error;
pub mod git;
2024-11-21 14:34:16 +00:00
pub mod path;
2024-11-21 10:58:26 +00:00
pub mod shell;
pub mod ssh;
pub mod user;
2024-08-14 14:58:16 +00:00
}
2024-11-21 14:34:16 +00:00
use crate::indicators::{error::*, git::*, path::*, shell::*, ssh::*, user::*};
2024-08-14 14:58:16 +00:00
2024-08-13 21:49:45 +00:00
fn main() -> std::io::Result<()> {
2024-11-21 10:58:26 +00:00
//let angle = "";
2024-08-15 15:05:40 +00:00
let args: Vec<String> = args().collect();
2024-11-21 10:58:26 +00:00
let shell: String = shell(args.clone());
2024-08-15 15:05:40 +00:00
2024-11-21 08:39:00 +00:00
let root_indicator = root_indicator();
2024-08-18 03:05:00 +00:00
2024-11-21 10:58:26 +00:00
let err: String = err(args.clone());
let err_indicator = err_indicator(err);
2024-08-18 03:05:00 +00:00
2024-11-21 08:39:00 +00:00
// SSH status
let ssh_char = ssh_char();
2024-08-15 15:05:40 +00:00
//Git status
2024-08-19 13:24:12 +00:00
let git_branch = get_git_branch();
2024-08-17 16:00:08 +00:00
let git_repo_root = get_git_root();
2024-08-19 13:24:12 +00:00
let git_repo_name = get_git_repo_name(&git_repo_root.clone()).truecolor(122, 68, 24);
let git_char = get_git_char(&git_branch);
2024-08-17 18:27:14 +00:00
//pwd
2024-11-21 14:34:16 +00:00
let homedir = homedir();
2024-08-17 18:27:14 +00:00
let pwd = current_dir()?;
let mut cur_dir = pwd.display().to_string();
2024-08-19 13:24:12 +00:00
cur_dir = cur_dir.replace(&git_repo_root, ""); // Remove git repo root
cur_dir = cur_dir.replace(&homedir, "~"); // Abreviate homedir with "~"
cur_dir = abrev_path(&cur_dir);
print!(
"{}{}{}{}{}{}{} ",
ssh_char,
get_shell_char(&shell).truecolor(75, 75, 75),
git_repo_name,
git_char,
cur_dir.italic().truecolor(82, 82, 82),
root_indicator,
err_indicator,
2024-08-14 21:03:53 +00:00
);
2024-08-13 21:49:45 +00:00
Ok(())
2024-08-19 13:24:12 +00:00
}