diff --git a/src/builtins/mod.rs b/src/builtins/mod.rs index 218f26e..addf4f6 100644 --- a/src/builtins/mod.rs +++ b/src/builtins/mod.rs @@ -5,6 +5,7 @@ use once_cell::unsync::Lazy; mod cd; mod change_prompt; mod exit; +mod pwd; pub struct BuiltinConfig { pub prompt_style: PromptStyle, @@ -27,6 +28,7 @@ const BUILTINS: Lazy)>> = Lazy::new(|| { ("cd", Box::new(cd::Cd)), ("change-prompt", Box::new(change_prompt::ChangePrompt)), ("exit", Box::new(exit::Exit)), + ("pwd", Box::new(pwd::Pwd)), ] }); diff --git a/src/builtins/pwd.rs b/src/builtins/pwd.rs new file mode 100644 index 0000000..e9f3cdb --- /dev/null +++ b/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) -> Result<(), ShellError> { + match std::env::current_dir() { + Ok(p) => println!("{}", p.display()), + Err(e) => return Err(ShellError::ExecuteFailure(e.to_string())), + } + Ok(()) + } +}