//use colored::{ColoredString, Colorize}; use colored::Colorize; use std::env::{args, current_dir, var_os}; mod indicators { pub mod error; pub mod git; pub mod shell; pub mod ssh; pub mod user; } use crate::indicators::{error::*, git::*, shell::*, ssh::*, user::*}; fn abrev_path(path: &str) -> String { let mut short_dir = path.to_string(); let slashes = path.matches('/').count(); if slashes > 3 { let parts: Vec<&str> = path.split('/').collect(); let len = parts.len() - 1; let mut ch1: String; for part in &parts[0..len] { if part.to_string() != "" { // to avoid the 1st "/" ch1 = part.chars().next().expect(part).to_string(); // 1st char of each part short_dir = short_dir.replace(part, &ch1); } } } short_dir } fn main() -> std::io::Result<()> { //let angle = "❯"; let args: Vec = args().collect(); let shell: String = shell(args.clone()); let root_indicator = root_indicator(); let err: String = err(args.clone()); let err_indicator = err_indicator(err); // SSH status let ssh_char = ssh_char(); //Git status let git_branch = get_git_branch(); let git_repo_root = get_git_root(); let git_repo_name = get_git_repo_name(&git_repo_root.clone()).truecolor(122, 68, 24); let git_char = get_git_char(&git_branch); //pwd let homedir = var_os("HOME") .expect("UnknownDir") .to_str() .expect("UnknownDir") .to_string(); let pwd = current_dir()?; let mut cur_dir = pwd.display().to_string(); 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, ); Ok(()) }