Abreviate pwd
This commit is contained in:
parent
2bf65b957b
commit
4eca128f2c
41
src/main.rs
41
src/main.rs
@ -1,22 +1,24 @@
|
|||||||
use std::env::current_dir as current_dir;
|
use std::env::current_dir as current_dir;
|
||||||
//use std::env::var_os as var_os;
|
use std::env::var_os as var_os;
|
||||||
use std::env::args as args;
|
use std::env::args as args;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let angle = "❯";
|
let angle = "❯";
|
||||||
let pwd = current_dir()?;
|
let pwd = current_dir()?;
|
||||||
let dir = pwd.display().to_string();
|
let mut dir = pwd.display().to_string();
|
||||||
let args: Vec<String> = args().collect();
|
let args: Vec<String> = args().collect();
|
||||||
let shell: String;
|
let shell: String;
|
||||||
|
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();
|
||||||
|
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
shell = args[1].clone();
|
shell = args[1].clone();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
shell = "none".to_string();
|
shell = "none".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
let shell_char = match shell.as_str() {
|
let shell_char = match shell.as_str() {
|
||||||
"bash" => "",
|
"bash" => "",
|
||||||
"zsh" => "",
|
"zsh" => "",
|
||||||
@ -25,20 +27,31 @@ fn main() -> std::io::Result<()> {
|
|||||||
"ion" => "",
|
"ion" => "",
|
||||||
_ => "",
|
_ => "",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dir = str::replace(&dir, &homedir, "~"); // Abreviate homedir with "~"
|
||||||
|
|
||||||
/*
|
let mut dir0 = dir.clone();
|
||||||
match var_os(USER).as_str() {
|
let slashes = dir.matches("/").count();
|
||||||
"root" => {
|
//println!("{}",slashes);
|
||||||
shell_char = shell_char.truecolor(255,53,94);
|
|
||||||
},
|
if slashes > 3 {
|
||||||
_ => {
|
// let mut dir0 = dir;
|
||||||
shell_char = shell_char.truecolor(54,178,91);
|
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;
|
||||||
|
|
||||||
print!("{} {}{} ",
|
print!("{} {}{} ",
|
||||||
shell_char.truecolor(75,75,75),
|
shell_char.truecolor(75,75,75),
|
||||||
dir.italic().truecolor(75,75,75),
|
dir0.italic().truecolor(75,75,75),
|
||||||
angle.truecolor(0, 255, 180),
|
angle.truecolor(0, 255, 180),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user