diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index 65a293d..b4972e3 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,13 +1,17 @@ | |||
1 | use std::env; | 1 | use std::env; |
2 | use tico::tico; | 2 | use tico::tico; |
3 | use git2::Repository; | 3 | use git2::{ Repository, Status }; |
4 | 4 | ||
5 | fn main() { | 5 | fn main() { |
6 | println!("{:?}", env::var("GIT_DIRTY")); | ||
6 | print!("{}", cwd()); | 7 | print!("{}", cwd()); |
7 | match vcs() { | 8 | let (branch, status) = match vcs_status() { |
8 | Some(br) => println!(" {}", br), | 9 | Some((x, y)) => { |
9 | None => println!() | 10 | (x, y) |
10 | } | 11 | }, |
12 | None => ("".into(), "".into()) | ||
13 | }; | ||
14 | println!(" {} {}", branch, status); | ||
11 | println!("{}", prompt_char()); | 15 | println!("{}", prompt_char()); |
12 | } | 16 | } |
13 | 17 | ||
@@ -32,7 +36,7 @@ fn prompt_char() -> String { | |||
32 | } | 36 | } |
33 | } | 37 | } |
34 | 38 | ||
35 | fn vcs() -> Option<String> { | 39 | fn vcs_status() -> Option<(String, String)> { |
36 | let current_dir = env::var("PWD").unwrap(); | 40 | let current_dir = env::var("PWD").unwrap(); |
37 | 41 | ||
38 | let repo = match Repository::open(current_dir) { | 42 | let repo = match Repository::open(current_dir) { |
@@ -41,12 +45,40 @@ fn vcs() -> Option<String> { | |||
41 | }; | 45 | }; |
42 | 46 | ||
43 | let reference = repo.head().unwrap(); | 47 | let reference = repo.head().unwrap(); |
48 | let mut branch; | ||
44 | 49 | ||
45 | if reference.is_branch() { | 50 | if reference.is_branch() { |
46 | Some(format!("{}", reference.shorthand().unwrap())) | 51 | branch = format!("{}", reference.shorthand().unwrap()); |
47 | } else { | 52 | } else { |
48 | let commit = reference.peel_to_commit().unwrap(); | 53 | let commit = reference.peel_to_commit().unwrap(); |
49 | let id = commit.id(); | 54 | let id = commit.id(); |
50 | Some(format!("{}", id)) | 55 | branch = format!("{}", id); |
56 | } | ||
57 | |||
58 | let mut repo_stat = String::new(); | ||
59 | |||
60 | let file_stats = repo.statuses(None).unwrap(); | ||
61 | for file in file_stats.iter() { | ||
62 | match file.status() { | ||
63 | Status::WT_NEW | | ||
64 | Status::WT_MODIFIED | | ||
65 | Status::WT_DELETED | | ||
66 | Status::WT_TYPECHANGE | | ||
67 | Status::WT_RENAMED => { | ||
68 | let stat_char = env::var("GIT_DIRTY").unwrap_or("×".into()); | ||
69 | repo_stat = stat_char; | ||
70 | break; | ||
71 | }, | ||
72 | Status::INDEX_NEW | | ||
73 | Status::INDEX_MODIFIED | | ||
74 | Status::INDEX_DELETED | | ||
75 | Status::INDEX_TYPECHANGE | | ||
76 | Status::INDEX_RENAMED => { | ||
77 | let stat_char = env::var("GIT_CLEAN").unwrap_or("·".into()); | ||
78 | repo_stat = stat_char; | ||
79 | } | ||
80 | _ => { } | ||
81 | } | ||
51 | } | 82 | } |
83 | return Some((branch, repo_stat)) | ||
52 | } | 84 | } |