comments cleanup

This commit is contained in:
Candifloss 2024-08-18 09:27:36 +05:30
parent 94559380d3
commit b63cee81b5

View File

@ -1,8 +1,6 @@
use std::env::{current_dir,var_os,args}; use std::env::{current_dir,var_os,args};
use colored::{Colorize,ColoredString}; use colored::{Colorize,ColoredString};
use std::process::Command; use std::process::Command;
//use std::path::PathBuf;
//use std::ffi::OsString;
fn get_shell_char (shell: String) -> String { fn get_shell_char (shell: String) -> String {
let shell_char = match shell.as_str() { let shell_char = match shell.as_str() {
@ -35,7 +33,6 @@ fn get_git_branch () -> String {
if git_err == "" { if git_err == "" {
git_status_output.split("\n").collect::<Vec<&str>>()[0] git_status_output.split("\n").collect::<Vec<&str>>()[0]
.split(" ").collect::<Vec<&str>>()[2].to_string() .split(" ").collect::<Vec<&str>>()[2].to_string()
//.truecolor(82,82,82);
} }
else { else {
"".to_string() "".to_string()
@ -64,7 +61,7 @@ fn get_git_root () -> String {
fn get_git_repo_name (git_repo_root: String) -> String { fn get_git_repo_name (git_repo_root: String) -> String {
let repo_path_split: Vec<&str> = git_repo_root.split("/").collect(); let repo_path_split: Vec<&str> = git_repo_root.split("/").collect();
let last_index = repo_path_split.len() - 1; let last_index = repo_path_split.len() - 1;
let git_repo_name = repo_path_split[last_index];//.truecolor(82,82,82); let git_repo_name = repo_path_split[last_index];
git_repo_name.to_string() git_repo_name.to_string()
} }
@ -89,8 +86,8 @@ fn abrev_path (path: String) -> String {
let mut ch1: String; let mut ch1: String;
for part in &parts[0..len] { for part in &parts[0..len] {
if part.to_string() != "" { // to avoid the 1st "/" if part.to_string() != "" { // to avoid the 1st "/"
ch1 = part.chars().next().expect(part).to_string(); // 1st char of each part ch1 = part.chars().next().expect(part).to_string(); // 1st char of each part
short_dir = short_dir.replace(part, &ch1); short_dir = short_dir.replace(part, &ch1);
} }
} }
@ -104,7 +101,7 @@ fn main() -> std::io::Result<()> {
//Root user indicator //Root user indicator
let user = var_os("USER").expect("UnknownUser").to_str().expect("UnknownUser").to_string(); let user = var_os("USER").expect("UnknownUser").to_str().expect("UnknownUser").to_string();
let mut err = ""; let mut err: String = "".to_string();
//Shell symbol //Shell symbol
let args: Vec<String> = args().collect(); let args: Vec<String> = args().collect();
@ -112,7 +109,7 @@ fn main() -> std::io::Result<()> {
if args.len() > 1 { if args.len() > 1 {
shell = args[1].clone(); shell = args[1].clone();
if args.len() > 2 { if args.len() > 2 {
err = args[2].as_str(); err = args[2].clone();
} }
} }
else { else {
@ -124,7 +121,7 @@ fn main() -> std::io::Result<()> {
_ => angle.truecolor(0, 255, 180), _ => angle.truecolor(0, 255, 180),
}; };
let err_indicator = match err { let err_indicator = match err.as_str() {
"0" => angle.truecolor(0, 255, 180), "0" => angle.truecolor(0, 255, 180),
_ => angle.truecolor(255, 53, 94), _ => angle.truecolor(255, 53, 94),
}; };
@ -141,17 +138,17 @@ fn main() -> std::io::Result<()> {
} }
//Git status //Git status
let git_branch = get_git_branch();//.clear(); let git_branch = get_git_branch();
let git_repo_root = get_git_root(); 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_repo_name = get_git_repo_name(git_repo_root.clone()).truecolor(122, 68, 24);
let git_char = get_git_char(git_branch); //.to_string()); let git_char = get_git_char(git_branch);
//pwd //pwd
let homedir = var_os("HOME").expect("UnknownDir").to_str().expect("UnknownDir").to_string(); let homedir = var_os("HOME").expect("UnknownDir").to_str().expect("UnknownDir").to_string();
let pwd = current_dir()?; let pwd = current_dir()?;
let mut cur_dir = pwd.display().to_string(); 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(&git_repo_root, ""); // Remove git repo root
cur_dir = cur_dir.replace(&homedir, "~"); // Abreviate homedir with "~" cur_dir = cur_dir.replace(&homedir, "~"); // Abreviate homedir with "~"
cur_dir = abrev_path(cur_dir); cur_dir = abrev_path(cur_dir);
print!("{}{}{}{}{}{}{} ", print!("{}{}{}{}{}{}{} ",
@ -159,9 +156,7 @@ fn main() -> std::io::Result<()> {
get_shell_char(shell).truecolor(75,75,75), get_shell_char(shell).truecolor(75,75,75),
git_repo_name, git_repo_name,
git_char, git_char,
//abrev_path(pwd,homedir).italic().truecolor(82,82,82),
cur_dir.italic().truecolor(82,82,82), cur_dir.italic().truecolor(82,82,82),
//angle.truecolor(0, 255, 180),
root_indicator, root_indicator,
err_indicator, err_indicator,
); );