aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cwd.rs9
-rw-r--r--src/main.rs11
2 files changed, 14 insertions, 6 deletions
diff --git a/src/cwd.rs b/src/cwd.rs
index 95b6659..157858c 100644
--- a/src/cwd.rs
+++ b/src/cwd.rs
@@ -2,8 +2,9 @@ use std::env;
2use tico::tico; 2use tico::tico;
3use colored::*; 3use colored::*;
4 4
5pub fn cwd() -> colored::ColoredString { 5pub fn cwd() -> Option<colored::ColoredString> {
6 let mut path = format!("{}", env::current_dir().unwrap_or("".into()).display()); 6 let path_env = env::current_dir().ok()?;
7 let mut path = format!("{}", path_env.display());
7 let home = env::var("HOME").unwrap(); 8 let home = env::var("HOME").unwrap();
8 let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into()); 9 let tilde_expand = env::var("EXPAND_TILDE").unwrap_or("0".into());
9 10
@@ -19,8 +20,8 @@ pub fn cwd() -> colored::ColoredString {
19 let cwd_shorten = env::var("SHORTEN_CWD").unwrap_or("1".into()); 20 let cwd_shorten = env::var("SHORTEN_CWD").unwrap_or("1".into());
20 let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into()); 21 let cwd_color = env::var("CWD_COLOR").unwrap_or("white".into());
21 match cwd_shorten.as_ref() { 22 match cwd_shorten.as_ref() {
22 "0" => return path.color(cwd_color), 23 "0" => return Some(path.color(cwd_color)),
23 _ => return tico(&path[..]).color(cwd_color) 24 _ => return Some(tico(&path[..]).color(cwd_color))
24 } 25 }
25 26
26} 27}
diff --git a/src/main.rs b/src/main.rs
index 0603cba..3096635 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@ mod vcs;
4mod venv; 4mod venv;
5 5
6use clap::{Arg, App}; 6use clap::{Arg, App};
7use colored::*;
7 8
8fn main() { 9fn main() {
9 let matches = App::new("Pista") 10 let matches = App::new("Pista")
@@ -29,7 +30,10 @@ fn main() {
29} 30}
30 31
31fn pista(zsh: bool) -> String { 32fn pista(zsh: bool) -> String {
32 let cwd = cwd::cwd(); 33 let cwd = match cwd::cwd() {
34 Some(c) => c,
35 None => "[directory does not exist]".color("red")
36 };
33 let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into())); 37 let (branch, status) = vcs::vcs_status().unwrap_or(("".into(), "".into()));
34 let venv = venv::get_name(); 38 let venv = venv::get_name();
35 let prompt_char = prompt_char::get_char(); 39 let prompt_char = prompt_char::get_char();
@@ -53,7 +57,10 @@ fn pista(zsh: bool) -> String {
53} 57}
54 58
55fn pista_minimal(zsh: bool) -> String { 59fn pista_minimal(zsh: bool) -> String {
56 let cwd = cwd::cwd(); 60 let cwd = match cwd::cwd() {
61 Some(c) => c,
62 None => "[directory does not exist]".color("red")
63 };
57 let vcs_tuple = vcs::vcs_status(); 64 let vcs_tuple = vcs::vcs_status();
58 let mut vcs_component = String::new(); 65 let mut vcs_component = String::new();
59 if let Some((branch, status)) = vcs_tuple { 66 if let Some((branch, status)) = vcs_tuple {