diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index 6ddfe0f..65a293d 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,8 +1,13 @@ | |||
1 | use std::env; | 1 | use std::env; |
2 | use tico::tico; | 2 | use tico::tico; |
3 | use git2::Repository; | ||
3 | 4 | ||
4 | fn main() { | 5 | fn main() { |
5 | println!("{}", cwd()); | 6 | print!("{}", cwd()); |
7 | match vcs() { | ||
8 | Some(br) => println!(" {}", br), | ||
9 | None => println!() | ||
10 | } | ||
6 | println!("{}", prompt_char()); | 11 | println!("{}", prompt_char()); |
7 | } | 12 | } |
8 | 13 | ||
@@ -27,5 +32,21 @@ fn prompt_char() -> String { | |||
27 | } | 32 | } |
28 | } | 33 | } |
29 | 34 | ||
30 | fn vcs() -> String { | 35 | fn vcs() -> Option<String> { |
36 | let current_dir = env::var("PWD").unwrap(); | ||
37 | |||
38 | let repo = match Repository::open(current_dir) { | ||
39 | Ok(r) => r, | ||
40 | Err(_) => return None | ||
41 | }; | ||
42 | |||
43 | let reference = repo.head().unwrap(); | ||
44 | |||
45 | if reference.is_branch() { | ||
46 | Some(format!("{}", reference.shorthand().unwrap())) | ||
47 | } else { | ||
48 | let commit = reference.peel_to_commit().unwrap(); | ||
49 | let id = commit.id(); | ||
50 | Some(format!("{}", id)) | ||
51 | } | ||
31 | } | 52 | } |