diff --git a/src/main.rs b/src/main.rs index 73e605a..87e73b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use crate::builtins::BuiltinConfig; use crate::prompt::Prompt; -use colored::*; +use colored::Colorize; use execute::interpret; use rustyline::config::Configurer; use rustyline::error::ReadlineError; @@ -26,7 +26,7 @@ fn main() -> Result<()> { let mut prompt = Prompt::new(); let mut config = BuiltinConfig::new(); - println!("Welcome, {}.", username().bright_green().bold()); + println!("\nWelcome, {}.", username().bright_green().bold()); loop { let readline = rl.readline(&prompt.get_prompt()); diff --git a/src/prompt.rs b/src/prompt.rs index d6fcb64..e1fc667 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -1,3 +1,4 @@ +use colored::Colorize; use std::env; #[derive(Clone)] @@ -17,7 +18,31 @@ impl PromptStyle { } fn fmt_default(&self) -> String { - "» ".to_string() + let current = env::current_dir().unwrap_or_default(); + let home = dirs::home_dir().unwrap_or_default(); + + let dir = if current.starts_with(home.clone()) { + let mut path = "~/".to_string(); + + path.push_str( + current + .as_path() + .strip_prefix(home) + .unwrap() + .to_str() + .unwrap_or_default(), + ); + + path + } else { + current.into_os_string().into_string().unwrap_or_default() + }; + + format!( + "\n{}\n{} ", + dir.bright_cyan().bold(), + "»".bright_green().bold() + ) } fn fmt_simple_directory(&self) -> String {