diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs index b4972e3..8bacacb 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | use std::env; | 1 | use std::env; |
2 | use tico::tico; | 2 | use tico::tico; |
3 | use git2::{ Repository, Status }; | 3 | use git2::{ Repository, Status }; |
4 | use colored::*; | ||
4 | 5 | ||
5 | fn main() { | 6 | fn main() { |
6 | println!("{:?}", env::var("GIT_DIRTY")); | 7 | println!("{:?}", env::var("GIT_DIRTY")); |
@@ -11,8 +12,8 @@ fn main() { | |||
11 | }, | 12 | }, |
12 | None => ("".into(), "".into()) | 13 | None => ("".into(), "".into()) |
13 | }; | 14 | }; |
14 | println!(" {} {}", branch, status); | 15 | println!(" {} {}", branch.green(), status.dimmed()); |
15 | println!("{}", prompt_char()); | 16 | print!("{}", prompt_char()); |
16 | } | 17 | } |
17 | 18 | ||
18 | fn cwd() -> String { | 19 | fn cwd() -> String { |
@@ -25,18 +26,18 @@ fn cwd() -> String { | |||
25 | } | 26 | } |
26 | } | 27 | } |
27 | 28 | ||
28 | fn prompt_char() -> String { | 29 | fn prompt_char() -> colored::ColoredString { |
29 | let user_char = env::var("PROMPT_CHAR").unwrap_or("$ ".into()); | 30 | let user_char = env::var("PROMPT_CHAR").unwrap_or("$ ".into()); |
30 | let root_char = env::var("PROMPT_CHAR_ROOT").unwrap_or("# ".into()); | 31 | let root_char = env::var("PROMPT_CHAR_ROOT").unwrap_or("# ".into()); |
31 | 32 | ||
32 | let euid = unsafe { libc::geteuid() }; | 33 | let euid = unsafe { libc::geteuid() }; |
33 | match euid { | 34 | match euid { |
34 | 0 => return root_char, | 35 | 0 => return root_char.red(), |
35 | _ => return user_char | 36 | _ => return user_char.green() |
36 | } | 37 | } |
37 | } | 38 | } |
38 | 39 | ||
39 | fn vcs_status() -> Option<(String, String)> { | 40 | fn vcs_status() -> Option<(colored::ColoredString, String)> { |
40 | let current_dir = env::var("PWD").unwrap(); | 41 | let current_dir = env::var("PWD").unwrap(); |
41 | 42 | ||
42 | let repo = match Repository::open(current_dir) { | 43 | let repo = match Repository::open(current_dir) { |
@@ -48,11 +49,11 @@ fn vcs_status() -> Option<(String, String)> { | |||
48 | let mut branch; | 49 | let mut branch; |
49 | 50 | ||
50 | if reference.is_branch() { | 51 | if reference.is_branch() { |
51 | branch = format!("{}", reference.shorthand().unwrap()); | 52 | branch = format!("{}", reference.shorthand().unwrap()).green(); |
52 | } else { | 53 | } else { |
53 | let commit = reference.peel_to_commit().unwrap(); | 54 | let commit = reference.peel_to_commit().unwrap(); |
54 | let id = commit.id(); | 55 | let id = commit.id(); |
55 | branch = format!("{}", id); | 56 | branch = format!("{}", id).yellow(); |
56 | } | 57 | } |
57 | 58 | ||
58 | let mut repo_stat = String::new(); | 59 | let mut repo_stat = String::new(); |