minor code changes

This commit is contained in:
Candifloss 2024-08-15 23:15:45 +05:30
parent bbcd54dd92
commit 927aeec3ba

View File

@ -7,23 +7,31 @@ use std::process::Command;
fn get_shell_char (shell: String) -> String {
let shell_char = match shell.as_str() {
"bash"|"/bin/bash"
=> "",
=> "",
"zsh"|"/bin/zsh"|"/usr/bin/zsh"|"-zsh"
=> "󰰶 ",
=> "󰰶 ",
"fish"
=> "󰈺 ",
=> "󰈺 ",
"nushell"
=> "",
=> "",
"ion"
=> "",
=> "",
"oursh"
=> "󱢇 ",
=> "󱢇 ",
_
=> "󱆃 ",
=> "󱆃 ",
};
shell_char.to_string()
}
fn get_git_char (git_branch: String) -> ColoredString {
match get_git_char.as_str() {
"main" => " 󰊢 ".truecolor(178,98,44),
"master" => " 󰊢 ".truecolor(196,132,29),
_ => " 󰊢 ".truecolor(82,82,82),
}
}
fn abrev_path (pwd: PathBuf, homedir: String) -> String {
let mut path = pwd.display().to_string();
path = path.replace(&homedir, "~"); // Abreviate homedir with "~"
@ -72,11 +80,9 @@ fn main() -> std::io::Result<()> {
//SSH shell indicator
let ssh_char:ColoredString;
//let mut ssh_char_space: String = "".to_string();
match var_os("SSH_TTY") {
Some(_val) => {
ssh_char = "".truecolor(0,150,180);
//ssh_char_space = " ".to_string();
},
None => {
ssh_char = "".truecolor(34,109,155);
@ -84,9 +90,9 @@ fn main() -> std::io::Result<()> {
}
//Git status
let mut git_char = "".truecolor(82,82,82);
let mut git_repo_name = "".truecolor(82,82,82);
let mut git_branch = "".truecolor(82,82,82);
let mut git_char = "".clear();
let mut git_repo_name = "".clear();
let mut git_branch = "".clear();
let git_status_cmd = Command::new("git")
.arg("status")
.output()
@ -117,15 +123,11 @@ fn main() -> std::io::Result<()> {
let last_index = repo_path_split.len() - 1;
git_repo_name = repo_path_split[last_index]
.truecolor(82,82,82);
//println!("LastInd:{}",last_index);
}
//println!("git_repo_path:{}\ngit_repo_err:{}",git_repo_path,git_repo_err);
}
//println!("git_repo_name:{}\ngit_branch:{}",git_repo_name,git_branch);
print!("{}{}{}{} {}{} ",
ssh_char,
//ssh_char_space,
get_shell_char(shell).truecolor(75,75,75),
git_repo_name,
git_char,