2024-08-14 17:31:23 +00:00
|
|
|
|
use std::env::current_dir;
|
|
|
|
|
use std::env::var_os;
|
|
|
|
|
use std::env::args;
|
2024-08-14 14:58:16 +00:00
|
|
|
|
use std::path::PathBuf;
|
2024-08-14 17:31:23 +00:00
|
|
|
|
//use std::ffi::OsString;
|
|
|
|
|
use colored::Colorize;
|
2024-08-14 20:40:03 +00:00
|
|
|
|
use colored::ColoredString;
|
2024-08-14 14:58:16 +00:00
|
|
|
|
|
|
|
|
|
fn get_shell_char (shell: String) -> String {
|
|
|
|
|
let shell_char = match shell.as_str() {
|
|
|
|
|
"bash"|"/bin/bash"
|
|
|
|
|
=> "",
|
2024-08-14 20:40:03 +00:00
|
|
|
|
"zsh"|"/bin/zsh"|"/usr/bin/zsh"|"-zsh"
|
2024-08-14 14:58:16 +00:00
|
|
|
|
=> "",
|
|
|
|
|
"fish"
|
|
|
|
|
=> "",
|
|
|
|
|
"nushell"
|
|
|
|
|
=> "",
|
|
|
|
|
"ion"
|
|
|
|
|
=> "",
|
|
|
|
|
"oursh"
|
|
|
|
|
=> "",
|
|
|
|
|
_
|
|
|
|
|
=> "",
|
|
|
|
|
};
|
|
|
|
|
shell_char.to_string()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn abrev_path (pwd: PathBuf, homedir: String) -> String {
|
|
|
|
|
let mut path = pwd.display().to_string();
|
|
|
|
|
path = path.replace(&homedir, "~"); // Abreviate homedir with "~"
|
|
|
|
|
let mut short_dir = path.clone();
|
|
|
|
|
|
|
|
|
|
let slashes = path.matches("/").count();
|
|
|
|
|
|
|
|
|
|
if slashes > 3 {
|
|
|
|
|
let parts: Vec<&str> = path.split("/").collect();
|
|
|
|
|
let len = parts.len() - 1;
|
|
|
|
|
let mut fch: String;
|
|
|
|
|
|
|
|
|
|
for p in &parts[0..len] {
|
|
|
|
|
let part = p;
|
2024-08-14 20:40:03 +00:00
|
|
|
|
if part.to_string() != "" { // to avoid the 1st "/"
|
|
|
|
|
fch = part.chars().next().expect(p).to_string(); // 1st char of p
|
2024-08-14 17:31:23 +00:00
|
|
|
|
short_dir = short_dir.replace(part, &fch);
|
|
|
|
|
}
|
2024-08-14 14:58:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
short_dir
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-13 21:49:45 +00:00
|
|
|
|
fn main() -> std::io::Result<()> {
|
|
|
|
|
let angle = "❯";
|
|
|
|
|
let pwd = current_dir()?;
|
|
|
|
|
let args: Vec<String> = args().collect();
|
|
|
|
|
let shell: String;
|
2024-08-14 17:31:23 +00:00
|
|
|
|
let _user = var_os("USER").expect("UnknownUser").to_str().expect("UnknownUser").to_string();
|
2024-08-14 14:58:16 +00:00
|
|
|
|
let homedir = var_os("HOME").expect("UnknownDir").to_str().expect("UnknownDir").to_string();
|
2024-08-14 20:40:03 +00:00
|
|
|
|
let ssh_char:ColoredString;
|
|
|
|
|
let mut ssh_char_space: String = "".to_string();
|
2024-08-14 11:19:47 +00:00
|
|
|
|
|
2024-08-13 21:49:45 +00:00
|
|
|
|
if args.len() > 1 {
|
|
|
|
|
shell = args[1].clone();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
shell = "none".to_string();
|
|
|
|
|
}
|
2024-08-14 17:31:23 +00:00
|
|
|
|
/*
|
|
|
|
|
if user == "root" {
|
|
|
|
|
println!("heh");
|
|
|
|
|
}*/
|
2024-08-14 20:40:03 +00:00
|
|
|
|
match var_os("SSH_TTY") {
|
|
|
|
|
Some(_val) => {
|
|
|
|
|
ssh_char = "".truecolor(34,109,155);
|
|
|
|
|
ssh_char_space = " ".to_string();
|
|
|
|
|
},
|
|
|
|
|
None => {
|
|
|
|
|
ssh_char = "".truecolor(34,109,155);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-08-14 11:19:47 +00:00
|
|
|
|
|
2024-08-14 20:40:03 +00:00
|
|
|
|
print!("{}{}{} {}{} ",
|
|
|
|
|
ssh_char,
|
|
|
|
|
ssh_char_space,
|
2024-08-14 14:58:16 +00:00
|
|
|
|
get_shell_char(shell).truecolor(75,75,75),
|
2024-08-14 20:40:03 +00:00
|
|
|
|
abrev_path(pwd,homedir).italic().truecolor(82,82,82),
|
2024-08-13 21:49:45 +00:00
|
|
|
|
angle.truecolor(0, 255, 180),
|
|
|
|
|
);
|
|
|
|
|
Ok(())
|
2024-08-14 14:58:16 +00:00
|
|
|
|
}
|