2024-08-13 21:49:45 +00:00
|
|
|
|
use std::env::current_dir as current_dir;
|
2024-08-14 11:19:47 +00:00
|
|
|
|
use std::env::var_os as var_os;
|
2024-08-13 21:49:45 +00:00
|
|
|
|
use std::env::args as args;
|
|
|
|
|
use colored::Colorize;
|
|
|
|
|
|
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
|
|
|
let angle = "❯";
|
|
|
|
|
let pwd = current_dir()?;
|
2024-08-14 11:19:47 +00:00
|
|
|
|
let mut dir = pwd.display().to_string();
|
2024-08-13 21:49:45 +00:00
|
|
|
|
let args: Vec<String> = args().collect();
|
|
|
|
|
let shell: String;
|
2024-08-14 11:19:47 +00:00
|
|
|
|
let user = var_os("USER").expect("noDir").to_str().expect("noDir").to_string();
|
|
|
|
|
let homedir = var_os("HOME").expect("noDir").to_str().expect("noDir").to_string();
|
|
|
|
|
|
2024-08-13 21:49:45 +00:00
|
|
|
|
if args.len() > 1 {
|
|
|
|
|
shell = args[1].clone();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
shell = "none".to_string();
|
|
|
|
|
}
|
2024-08-14 11:19:47 +00:00
|
|
|
|
|
2024-08-13 21:49:45 +00:00
|
|
|
|
let shell_char = match shell.as_str() {
|
|
|
|
|
"bash" => "",
|
|
|
|
|
"zsh" => "",
|
|
|
|
|
"fish" => "",
|
|
|
|
|
"nushell" => "",
|
|
|
|
|
"ion" => "",
|
|
|
|
|
_ => "",
|
|
|
|
|
};
|
2024-08-14 11:19:47 +00:00
|
|
|
|
|
|
|
|
|
dir = str::replace(&dir, &homedir, "~"); // Abreviate homedir with "~"
|
2024-08-13 21:49:45 +00:00
|
|
|
|
|
2024-08-14 11:19:47 +00:00
|
|
|
|
let mut dir0 = dir.clone();
|
|
|
|
|
let slashes = dir.matches("/").count();
|
|
|
|
|
//println!("{}",slashes);
|
2024-08-13 21:49:45 +00:00
|
|
|
|
|
2024-08-14 11:19:47 +00:00
|
|
|
|
if slashes > 3 {
|
|
|
|
|
// let mut dir0 = dir;
|
|
|
|
|
let parts: Vec<&str> = dir.split("/").collect();
|
|
|
|
|
let len = parts.len() - 1;
|
|
|
|
|
let mut fch: String;
|
|
|
|
|
|
|
|
|
|
for p in &parts[0..len] {
|
|
|
|
|
let part = p;
|
|
|
|
|
fch = part.chars().next().expect("REASON").to_string(); //1st char of p
|
|
|
|
|
dir0 = str::replace(&dir0, part, &fch);
|
|
|
|
|
//println!("{}__{}__{}",p,fch,dir0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//dir = dir0;
|
|
|
|
|
|
2024-08-13 21:49:45 +00:00
|
|
|
|
print!("{} {}{} ",
|
|
|
|
|
shell_char.truecolor(75,75,75),
|
2024-08-14 11:19:47 +00:00
|
|
|
|
dir0.italic().truecolor(75,75,75),
|
2024-08-13 21:49:45 +00:00
|
|
|
|
angle.truecolor(0, 255, 180),
|
|
|
|
|
);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|