Browse Source

feat: add pwd builtin command

main
fdai7375 2 years ago
parent
commit
9c24b7ff26
  1. 2
      src/builtins/mod.rs
  2. 15
      src/builtins/pwd.rs

2
src/builtins/mod.rs

@ -5,6 +5,7 @@ use once_cell::unsync::Lazy;
mod cd; mod cd;
mod change_prompt; mod change_prompt;
mod exit; mod exit;
mod pwd;
pub struct BuiltinConfig { pub struct BuiltinConfig {
pub prompt_style: PromptStyle, pub prompt_style: PromptStyle,
@ -27,6 +28,7 @@ const BUILTINS: Lazy<Vec<(&str, Box<dyn Builtin>)>> = Lazy::new(|| {
("cd", Box::new(cd::Cd)), ("cd", Box::new(cd::Cd)),
("change-prompt", Box::new(change_prompt::ChangePrompt)), ("change-prompt", Box::new(change_prompt::ChangePrompt)),
("exit", Box::new(exit::Exit)), ("exit", Box::new(exit::Exit)),
("pwd", Box::new(pwd::Pwd)),
] ]
}); });

15
src/builtins/pwd.rs

@ -0,0 +1,15 @@
use crate::error::ShellError;
use super::{Builtin, BuiltinConfig};
pub struct Pwd;
impl Builtin for Pwd {
fn execute(&mut self, _: &mut BuiltinConfig, _: Vec<String>) -> Result<(), ShellError> {
match std::env::current_dir() {
Ok(p) => println!("{}", p.display()),
Err(e) => return Err(ShellError::ExecuteFailure(e.to_string())),
}
Ok(())
}
}
Loading…
Cancel
Save