diff options
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/main.rs | 31 |
2 files changed, 28 insertions, 6 deletions
@@ -1,5 +1,5 @@ | |||
1 | [package] | 1 | [package] |
2 | name = "prompt" | 2 | name = "pista" |
3 | version = "0.1.0" | 3 | version = "0.1.0" |
4 | authors = ["NerdyPepper <[email protected]>"] | 4 | authors = ["NerdyPepper <[email protected]>"] |
5 | edition = "2018" | 5 | edition = "2018" |
@@ -10,3 +10,4 @@ tico = "1.0.0" | |||
10 | libc = "0.2.55" | 10 | libc = "0.2.55" |
11 | colored = "1.8.0" | 11 | colored = "1.8.0" |
12 | git2 = "0.8.0" | 12 | git2 = "0.8.0" |
13 | clap = "2.33.0" | ||
diff --git a/src/main.rs b/src/main.rs index e0b8f41..cee0c21 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -3,8 +3,24 @@ mod prompt_char; | |||
3 | mod vcs; | 3 | mod vcs; |
4 | mod venv; | 4 | mod venv; |
5 | 5 | ||
6 | use clap::{Arg, App}; | ||
7 | |||
6 | fn main() { | 8 | fn main() { |
7 | println!("{}", pista()); | 9 | let matches = App::new("Pista") |
10 | .version(env!("CARGO_PKG_VERSION")) | ||
11 | .author(env!("CARGO_PKG_AUTHORS")) | ||
12 | .about(env!("CARGO_PKG_DESCRIPTION")) | ||
13 | .arg(Arg::with_name("minimal") | ||
14 | .short("m") | ||
15 | .long("minimal") | ||
16 | .help("use minimal variant") | ||
17 | ) | ||
18 | .get_matches(); | ||
19 | if matches.is_present("minimal") { | ||
20 | println!("{}", pista_minimal()); | ||
21 | } else { | ||
22 | println!("{}", pista()); | ||
23 | } | ||
8 | } | 24 | } |
9 | 25 | ||
10 | fn pista() -> String { | 26 | fn pista() -> String { |
@@ -23,13 +39,18 @@ fn pista() -> String { | |||
23 | 39 | ||
24 | fn pista_minimal() -> String { | 40 | fn pista_minimal() -> String { |
25 | let cwd = cwd::cwd(); | 41 | let cwd = cwd::cwd(); |
26 | let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into())); | 42 | let vcs_tuple = vcs::vcs_status(); |
43 | let mut vcs_component = String::new(); | ||
44 | if let Some((branch, status)) = vcs_tuple { | ||
45 | vcs_component = format!(" [{} {}] ", branch, status); | ||
46 | } else { | ||
47 | vcs_component.push(' '); | ||
48 | } | ||
27 | let venv = venv::get_name(); | 49 | let venv = venv::get_name(); |
28 | let prompt_char = prompt_char::get_char(); | 50 | let prompt_char = prompt_char::get_char(); |
29 | format!("{cwd} {branch}{status}{venv}{pchar}", | 51 | format!("{cwd}{vcs}{venv}{pchar} ", |
30 | cwd=cwd, | 52 | cwd=cwd, |
31 | branch=branch, | 53 | vcs=vcs_component, |
32 | status=status, | ||
33 | venv=venv, | 54 | venv=venv, |
34 | pchar=prompt_char | 55 | pchar=prompt_char |
35 | ) | 56 | ) |