Initial commit
This commit is contained in:
commit
8439057884
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
Cargo.lock
|
|
@ -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]
|
|
@ -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),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue