diff options
author | Akshay <[email protected]> | 2020-02-03 13:36:27 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2020-02-03 13:36:27 +0000 |
commit | 4b147b4656135a04d2a4c2347e59f04d4f388d26 (patch) | |
tree | ea47e5789c9a974e18530bcdb7c30f9890dd80fc | |
parent | 2fa64b1b019398dcf97a9a7e79378fbf6199b3f3 (diff) |
new links, rustfmt
-rw-r--r-- | readme.md | 2 | ||||
-rw-r--r-- | src/main.rs | 86 |
2 files changed, 48 insertions, 40 deletions
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | > a simple {bash, zsh} prompt for programmers | 3 | > a simple {bash, zsh} prompt for programmers |
4 | 4 | ||
5 | ![pista.png](https://files.nerdypepper.tech/GZ.png) | 5 | ![pista.png](https://u.peppe.rs/GZ.png) |
6 | 6 | ||
7 | ### features | 7 | ### features |
8 | 8 | ||
diff --git a/src/main.rs b/src/main.rs index 3096635..b839325 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -3,7 +3,7 @@ mod prompt_char; | |||
3 | mod vcs; | 3 | mod vcs; |
4 | mod venv; | 4 | mod venv; |
5 | 5 | ||
6 | use clap::{Arg, App}; | 6 | use clap::{App, Arg}; |
7 | use colored::*; | 7 | use colored::*; |
8 | 8 | ||
9 | fn main() { | 9 | fn main() { |
@@ -11,15 +11,17 @@ fn main() { | |||
11 | .version(env!("CARGO_PKG_VERSION")) | 11 | .version(env!("CARGO_PKG_VERSION")) |
12 | .author(env!("CARGO_PKG_AUTHORS")) | 12 | .author(env!("CARGO_PKG_AUTHORS")) |
13 | .about(env!("CARGO_PKG_DESCRIPTION")) | 13 | .about(env!("CARGO_PKG_DESCRIPTION")) |
14 | .arg(Arg::with_name("minimal") | 14 | .arg( |
15 | .short("m") | 15 | Arg::with_name("minimal") |
16 | .long("minimal") | 16 | .short("m") |
17 | .help("use minimal variant") | 17 | .long("minimal") |
18 | .help("use minimal variant"), | ||
18 | ) | 19 | ) |
19 | .arg(Arg::with_name("zsh") | 20 | .arg( |
20 | .short("z") | 21 | Arg::with_name("zsh") |
21 | .long("zsh") | 22 | .short("z") |
22 | .help("Use ZSH formatting") | 23 | .long("zsh") |
24 | .help("Use ZSH formatting"), | ||
23 | ) | 25 | ) |
24 | .get_matches(); | 26 | .get_matches(); |
25 | if matches.is_present("minimal") { | 27 | if matches.is_present("minimal") { |
@@ -32,34 +34,36 @@ fn main() { | |||
32 | fn pista(zsh: bool) -> String { | 34 | fn pista(zsh: bool) -> String { |
33 | let cwd = match cwd::cwd() { | 35 | let cwd = match cwd::cwd() { |
34 | Some(c) => c, | 36 | Some(c) => c, |
35 | None => "[directory does not exist]".color("red") | 37 | None => "[directory does not exist]".color("red"), |
36 | }; | 38 | }; |
37 | let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into())); | 39 | let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into())); |
38 | let venv = venv::get_name(); | 40 | let venv = venv::get_name(); |
39 | let prompt_char = prompt_char::get_char(); | 41 | let prompt_char = prompt_char::get_char(); |
40 | if zsh { | 42 | if zsh { |
41 | format!("%{{{cwd} {branch} {status}%}} %{{\n{venv}{pchar}%}} ", | 43 | format!( |
42 | cwd=cwd, | 44 | "%{{{cwd} {branch} {status}%}} %{{\n{venv}{pchar}%}} ", |
43 | branch=branch, | 45 | cwd = cwd, |
44 | status=status, | 46 | branch = branch, |
45 | venv=venv, | 47 | status = status, |
46 | pchar=prompt_char | 48 | venv = venv, |
47 | ) | 49 | pchar = prompt_char |
50 | ) | ||
48 | } else { | 51 | } else { |
49 | format!("{cwd} {branch} {status}\n{venv}{pchar} ", | 52 | format!( |
50 | cwd=cwd, | 53 | "{cwd} {branch} {status}\n{venv}{pchar} ", |
51 | branch=branch, | 54 | cwd = cwd, |
52 | status=status, | 55 | branch = branch, |
53 | venv=venv, | 56 | status = status, |
54 | pchar=prompt_char | 57 | venv = venv, |
55 | ) | 58 | pchar = prompt_char |
59 | ) | ||
56 | } | 60 | } |
57 | } | 61 | } |
58 | 62 | ||
59 | fn pista_minimal(zsh: bool) -> String { | 63 | fn pista_minimal(zsh: bool) -> String { |
60 | let cwd = match cwd::cwd() { | 64 | let cwd = match cwd::cwd() { |
61 | Some(c) => c, | 65 | Some(c) => c, |
62 | None => "[directory does not exist]".color("red") | 66 | None => "[directory does not exist]".color("red"), |
63 | }; | 67 | }; |
64 | let vcs_tuple = vcs::vcs_status(); | 68 | let vcs_tuple = vcs::vcs_status(); |
65 | let mut vcs_component = String::new(); | 69 | let mut vcs_component = String::new(); |
@@ -71,25 +75,28 @@ fn pista_minimal(zsh: bool) -> String { | |||
71 | let venv = venv::get_name(); | 75 | let venv = venv::get_name(); |
72 | let prompt_char = prompt_char::get_char(); | 76 | let prompt_char = prompt_char::get_char(); |
73 | if zsh { | 77 | if zsh { |
74 | let fmt = format!("{cwd}{vcs}{venv}{pchar} ", | 78 | let fmt = format!( |
75 | cwd=cwd, | 79 | "{cwd}{vcs}{venv}{pchar} ", |
76 | vcs=vcs_component, | 80 | cwd = cwd, |
77 | venv=venv, | 81 | vcs = vcs_component, |
78 | pchar=prompt_char | 82 | venv = venv, |
83 | pchar = prompt_char | ||
79 | ); | 84 | ); |
80 | let mut ret = String::new(); | 85 | let mut ret = String::new(); |
81 | let mut color = false; | 86 | let mut color = false; |
82 | for ch in fmt.chars() { | 87 | for ch in fmt.chars() { |
83 | if color { | 88 | if color { |
84 | if ch == 'm' { // colors always end with m | 89 | if ch == 'm' { |
90 | // colors always end with m | ||
85 | ret.push_str("m%}"); | 91 | ret.push_str("m%}"); |
86 | color = false; | 92 | color = false; |
87 | } else { | 93 | } else { |
88 | ret.push(ch) | 94 | ret.push(ch) |
89 | } | 95 | } |
90 | } else { | 96 | } else { |
91 | if ch == 0x1b_u8.into() { // ESC char, always starts colors | 97 | if ch == 0x1b_u8.into() { |
92 | ret.push_str(&format!("%{{{esc}", esc=ch)); | 98 | // ESC char, always starts colors |
99 | ret.push_str(&format!("%{{{esc}", esc = ch)); | ||
93 | color = true; | 100 | color = true; |
94 | } else { | 101 | } else { |
95 | ret.push(ch); | 102 | ret.push(ch); |
@@ -98,11 +105,12 @@ fn pista_minimal(zsh: bool) -> String { | |||
98 | } | 105 | } |
99 | ret | 106 | ret |
100 | } else { | 107 | } else { |
101 | format!("{cwd}{vcs}{venv}{pchar} ", | 108 | format!( |
102 | cwd=cwd, | 109 | "{cwd}{vcs}{venv}{pchar} ", |
103 | vcs=vcs_component, | 110 | cwd = cwd, |
104 | venv=venv, | 111 | vcs = vcs_component, |
105 | pchar=prompt_char | 112 | venv = venv, |
106 | ) | 113 | pchar = prompt_char |
114 | ) | ||
107 | } | 115 | } |
108 | } | 116 | } |