From 22645fe49fcf488b46fbbcfae7d189c5c9c8c350 Mon Sep 17 00:00:00 2001 From: Rory Dudley Date: Fri, 16 Feb 2024 22:54:48 -0700 Subject: Change directories Added logic to change directories with 'cd'. --- src/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.rs b/src/main.rs index f78e54d..1ff551c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,6 +57,25 @@ fn eval(paths: &[&str], prompt: &str) { } } + // Check if user wants to change directories + if cmd == "cd" { + let path = match args.first() { + Some(str) => str, + None => { + println!("cd: Must specify a path"); + continue; + } + }; + match std::env::set_current_dir(path) { + Ok(_) => {} + Err(_) => { + println!("cd: Unable to change into {}", path); + continue; + } + } + continue; + } + // Check if the command exists let cmd = match bins.iter().find(|b| b.split("/").last().unwrap() == cmd) { Some(cmd) => cmd, -- cgit v1.2.3