aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNerdyPepper <[email protected]>2019-05-19 17:10:33 +0100
committerNerdyPepper <[email protected]>2019-05-19 17:10:33 +0100
commitdf33df6c95471379dba7312cbacaf44f7bb4f74d (patch)
tree0852c42f763c6ecf893c1572121736b47258c25b /src
parent01ede50477eee80767717592a738db772d25b631 (diff)
added vcs status
Diffstat (limited to 'src')
-rw-r--r--src/main.rs25
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 @@
1use std::env; 1use std::env;
2use tico::tico; 2use tico::tico;
3use git2::Repository;
3 4
4fn main() { 5fn 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
30fn vcs() -> String { 35fn 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}