From bbe000158dac6868358b089f51ea1b4ed15b1372 Mon Sep 17 00:00:00 2001 From: fdai7451 Date: Sat, 21 Jan 2023 16:59:33 +0100 Subject: [PATCH] feat: add simple directory prompt --- src/builtins/change_prompt.rs | 3 +++ src/prompt.rs | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/builtins/change_prompt.rs b/src/builtins/change_prompt.rs index 014355a..4eae628 100644 --- a/src/builtins/change_prompt.rs +++ b/src/builtins/change_prompt.rs @@ -13,6 +13,9 @@ impl Builtin for ChangePrompt { } else if let Some(style) = args.get(0) { match style.to_lowercase().as_str() { "none" => config.prompt_style = PromptStyle::None, + "simple-directory" | "simple_directory" | "simpledirectory" => { + config.prompt_style = PromptStyle::SimpleDirectory + } _ => { return Err(ShellError::ExecuteFailure(format!( "{} is not a valid prompt style", diff --git a/src/prompt.rs b/src/prompt.rs index 9b6a0be..0d88615 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -3,18 +3,24 @@ use std::path::PathBuf; #[derive(Clone)] pub enum PromptStyle { None, + SimpleDirectory, } impl PromptStyle { pub fn fmt_style(&self, path: PathBuf) -> String { match self { PromptStyle::None => self.fmt_none(path), + PromptStyle::SimpleDirectory => self.fmt_simple_directory(path), } } fn fmt_none(&self, _: PathBuf) -> String { return "» ".to_string(); } + + fn fmt_simple_directory(&self, path: PathBuf) -> String { + return format!("{} » ", path.to_string_lossy()); + } } pub struct Prompt {