summaryrefslogtreecommitdiffstats
path: root/src/builtins.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-25 15:39:08 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-25 15:39:08 -0500
commita875058500cc93f4d18bd5481d94987232bfbc2a (patch)
tree7ae8781f2f5aac00c7c087481e838967bb47eb07 /src/builtins.rs
parent000d3619847673cb66c8dd84fce675386f894c75 (diff)
downloadnbsh-a875058500cc93f4d18bd5481d94987232bfbc2a.tar.gz
nbsh-a875058500cc93f4d18bd5481d94987232bfbc2a.zip
rearrange some things
Diffstat (limited to 'src/builtins.rs')
-rw-r--r--src/builtins.rs47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/builtins.rs b/src/builtins.rs
deleted file mode 100644
index e8f87da..0000000
--- a/src/builtins.rs
+++ /dev/null
@@ -1,47 +0,0 @@
-pub fn is(exe: &str) -> bool {
- matches!(exe, "cd")
-}
-
-pub fn run<'a>(exe: &str, args: impl IntoIterator<Item = &'a str>) -> u8 {
- match exe {
- "cd" => impls::cd(
- args.into_iter()
- .map(std::convert::AsRef::as_ref)
- .next()
- .unwrap_or(""),
- ),
- _ => unreachable!(),
- }
-}
-
-mod impls {
- pub fn cd(dir: &str) -> u8 {
- let dir = if dir.is_empty() {
- home()
- } else if dir.starts_with('~') {
- let path: std::path::PathBuf = dir.into();
- if let std::path::Component::Normal(prefix) =
- path.components().next().unwrap()
- {
- if prefix.to_str() == Some("~") {
- home().join(path.strip_prefix(prefix).unwrap())
- } else {
- // TODO
- return 1;
- }
- } else {
- unreachable!()
- }
- } else {
- dir.into()
- };
- match std::env::set_current_dir(dir) {
- Ok(()) => 0,
- Err(_) => 1,
- }
- }
-
- fn home() -> std::path::PathBuf {
- std::env::var_os("HOME").unwrap().into()
- }
-}