diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-09-21 17:40:05 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-09-21 17:48:33 +0300 |
commit | 42cca401d21085709da7333069dbfcca99177d8d (patch) | |
tree | 9addbac29cdce1e3430b40c267f5c6d4d816a5d2 /src/builtins.rs | |
download | rshell-42cca401d21085709da7333069dbfcca99177d8d.tar.xz |
Initial commit
Diffstat (limited to 'src/builtins.rs')
-rw-r--r-- | src/builtins.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/builtins.rs b/src/builtins.rs new file mode 100644 index 0000000..4ef2416 --- /dev/null +++ b/src/builtins.rs @@ -0,0 +1,10 @@ +use std::path::Path; + +pub fn cd(args: std::str::SplitWhitespace) -> std::path::PathBuf { + let new_dir = args.peekable().peek().map_or("/", |x| *x); + let root = Path::new(new_dir); + if let Err(e) = std::env::set_current_dir(&root) { + eprintln!("{}", e); + } + root.to_path_buf() +} |