From af5b620f472ceefc2408f59fdf30b85e92390f7f Mon Sep 17 00:00:00 2001 From: NerdyPepper Date: Mon, 20 May 2019 17:23:48 +0530 Subject: support 3 rpeo states, add more config options --- src/main.rs | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main.rs b/src/main.rs index d5a0ce1..33d706d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,12 +5,7 @@ use colored::*; fn main() { print!("{}", cwd()); - let (branch, status) = match vcs_status() { - Some((x, y)) => { - (x, y) - }, - None => ("".into(), "".into()) - }; + let (branch, status) = vcs_status().unwrap_or(("".into(), "".into())); println!(" {} {}", branch, status.dimmed()); print!("{} ", prompt_char()); } @@ -45,7 +40,7 @@ fn prompt_char() -> colored::ColoredString { } } -fn vcs_status() -> Option<(colored::ColoredString, String)> { +fn vcs_status() -> Option<(colored::ColoredString, colored::ColoredString)> { let current_dir = env::var("PWD").unwrap(); let repo = match Repository::open(current_dir) { @@ -57,35 +52,40 @@ fn vcs_status() -> Option<(colored::ColoredString, String)> { let mut branch; if reference.is_branch() { - branch = format!("{}", reference.shorthand().unwrap()).green(); + branch = format!("{}", reference.shorthand().unwrap()).bright_black(); } else { let commit = reference.peel_to_commit().unwrap(); let id = commit.id(); - branch = format!("{:.6}", id).yellow(); + branch = format!("{:.6}", id).bright_black(); } - let mut repo_stat = String::new(); + let mut repo_stat = "".white(); + let git_clean_color = env::var("GIT_CLEAN_COLOR").unwrap_or("green".into()); + let git_wt_modified_color = env::var("GIT_WT_MODIFIED_COLOR").unwrap_or("red".into()); + let git_index_modified_color = env::var("GIT_INDEX_MODIFIED_COLOR").unwrap_or("yellow".into()); let file_stats = repo.statuses(None).unwrap(); for file in file_stats.iter() { match file.status() { - Status::WT_NEW | - Status::WT_MODIFIED | - Status::WT_DELETED | - Status::WT_TYPECHANGE | - Status::WT_RENAMED | - Status::INDEX_NEW | - Status::INDEX_MODIFIED | - Status::INDEX_DELETED | - Status::INDEX_TYPECHANGE | - Status::INDEX_RENAMED => { - let stat_char = env::var("GIT_DIRTY").unwrap_or("×".into()); - repo_stat = stat_char; - break; - }, + // STATE: unstaged (working tree modified) + Status::WT_NEW | Status::WT_MODIFIED | + Status::WT_DELETED | Status::WT_TYPECHANGE | + Status::WT_RENAMED => { + let stat_char = env::var("GIT_WT_MODIFIED").unwrap_or("×".into()); + repo_stat = stat_char.color(&git_wt_modified_color[..]); + break; + }, + // STATE: staged (changes added to index) + Status::INDEX_NEW | Status::INDEX_MODIFIED | + Status::INDEX_DELETED | Status::INDEX_TYPECHANGE | + Status::INDEX_RENAMED => { + let stat_char = env::var("GIT_INDEX_MODIFIED").unwrap_or("±".into()); + repo_stat = stat_char.color(&git_index_modified_color[..]); + }, + // STATE: comitted (changes have been saved in the repo) _ => { let stat_char = env::var("GIT_CLEAN").unwrap_or("·".into()); - repo_stat = stat_char; + repo_stat = stat_char.color(&git_clean_color[..]); } } } -- cgit v1.2.3