Browse Source

feat: add simple directory prompt

main
fdai7451 2 years ago
parent
commit
19c80dd121
  1. 3
      src/builtins/change_prompt.rs
  2. 6
      src/prompt.rs

3
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",

6
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 {

Loading…
Cancel
Save