Initial commit

This commit is contained in:
g1n 2021-07-19 11:59:20 +00:00
commit 8439057884
3 changed files with 50 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
Cargo.lock

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "grsh"
version = "0.1.0"
authors = ["g1n <g1n@ttm.sh>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

39
src/main.rs Normal file
View File

@ -0,0 +1,39 @@
use std::io::{self, stdout, Write};
use std::env;
use std::process::Command;
use std::path::Path;
fn main() {
loop {
print!("$ ");
io::stdout().flush();
let mut input = String::new();
io::stdin().read_line(&mut input).unwrap();
let mut parts = input.trim().split_whitespace();
let command = parts.next().unwrap();
let args = parts;
match command {
"cd" => {
let new_dir = args.peekable().peek().map_or("/", |x| *x);
let root = Path::new(new_dir);
if let Err(e) = env::set_current_dir(&root) {
eprintln!("{}", e);
}
},
"exit" => return,
command => {
let mut child = Command::new(command)
.args(args)
.spawn();
match child {
Ok(mut child) => { child.wait(); },
Err(e) => eprintln!("{}", e),
};
}
}
}
}