aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-05-20 12:53:48 +0100
committerNerdyPepper <[email protected]>2019-05-20 12:53:48 +0100
commitaf5b620f472ceefc2408f59fdf30b85e92390f7f (patch)
tree124bee4758cf604b7fcc569685ce3713c67741db /src/main.rs
parent72954b99aee3371bb627d91894ca2d6d3326d99d (diff)
support 3 rpeo states, add more config options
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs50
1 files 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::*;
5 5
6fn main() { 6fn main() {
7 print!("{}", cwd()); 7 print!("{}", cwd());
8 let (branch, status) = match vcs_status() { 8 let (branch, status) = vcs_status().unwrap_or(("".into(), "".into()));
9 Some((x, y)) => {
10 (x, y)
11 },
12 None => ("".into(), "".into())
13 };
14 println!(" {} {}", branch, status.dimmed()); 9 println!(" {} {}", branch, status.dimmed());
15 print!("{} ", prompt_char()); 10 print!("{} ", prompt_char());
16} 11}
@@ -45,7 +40,7 @@ fn prompt_char() -> colored::ColoredString {
45 } 40 }
46} 41}
47 42
48fn vcs_status() -> Option<(colored::ColoredString, String)> { 43fn vcs_status() -> Option<(colored::ColoredString, colored::ColoredString)> {
49 let current_dir = env::var("PWD").unwrap(); 44 let current_dir = env::var("PWD").unwrap();
50 45
51 let repo = match Repository::open(current_dir) { 46 let repo = match Repository::open(current_dir) {
@@ -57,35 +52,40 @@ fn vcs_status() -> Option<(colored::ColoredString, String)> {
57 let mut branch; 52 let mut branch;
58 53
59 if reference.is_branch() { 54 if reference.is_branch() {
60 branch = format!("{}", reference.shorthand().unwrap()).green(); 55 branch = format!("{}", reference.shorthand().unwrap()).bright_black();
61 } else { 56 } else {
62 let commit = reference.peel_to_commit().unwrap(); 57 let commit = reference.peel_to_commit().unwrap();
63 let id = commit.id(); 58 let id = commit.id();
64 branch = format!("{:.6}", id).yellow(); 59 branch = format!("{:.6}", id).bright_black();
65 } 60 }
66 61
67 let mut repo_stat = String::new(); 62 let mut repo_stat = "".white();
63 let git_clean_color = env::var("GIT_CLEAN_COLOR").unwrap_or("green".into());
64 let git_wt_modified_color = env::var("GIT_WT_MODIFIED_COLOR").unwrap_or("red".into());
65 let git_index_modified_color = env::var("GIT_INDEX_MODIFIED_COLOR").unwrap_or("yellow".into());
68 66
69 let file_stats = repo.statuses(None).unwrap(); 67 let file_stats = repo.statuses(None).unwrap();
70 for file in file_stats.iter() { 68 for file in file_stats.iter() {
71 match file.status() { 69 match file.status() {
72 Status::WT_NEW | 70 // STATE: unstaged (working tree modified)
73 Status::WT_MODIFIED | 71 Status::WT_NEW | Status::WT_MODIFIED |
74 Status::WT_DELETED | 72 Status::WT_DELETED | Status::WT_TYPECHANGE |
75 Status::WT_TYPECHANGE | 73 Status::WT_RENAMED => {
76 Status::WT_RENAMED | 74 let stat_char = env::var("GIT_WT_MODIFIED").unwrap_or("×".into());
77 Status::INDEX_NEW | 75 repo_stat = stat_char.color(&git_wt_modified_color[..]);
78 Status::INDEX_MODIFIED | 76 break;
79 Status::INDEX_DELETED | 77 },
80 Status::INDEX_TYPECHANGE | 78 // STATE: staged (changes added to index)
81 Status::INDEX_RENAMED => { 79 Status::INDEX_NEW | Status::INDEX_MODIFIED |
82 let stat_char = env::var("GIT_DIRTY").unwrap_or("×".into()); 80 Status::INDEX_DELETED | Status::INDEX_TYPECHANGE |
83 repo_stat = stat_char; 81 Status::INDEX_RENAMED => {
84 break; 82 let stat_char = env::var("GIT_INDEX_MODIFIED").unwrap_or("±".into());
85 }, 83 repo_stat = stat_char.color(&git_index_modified_color[..]);
84 },
85 // STATE: comitted (changes have been saved in the repo)
86 _ => { 86 _ => {
87 let stat_char = env::var("GIT_CLEAN").unwrap_or("·".into()); 87 let stat_char = env::var("GIT_CLEAN").unwrap_or("·".into());
88 repo_stat = stat_char; 88 repo_stat = stat_char.color(&git_clean_color[..]);
89 } 89 }
90 } 90 }
91 } 91 }