ableos_userland/programs/shell/src/main.rs

58 lines
1.6 KiB
Rust
Raw Normal View History

2022-12-03 12:15:03 -06:00
use std::{
env,
io::{stdin, stdout, Read, Write},
path::Path,
process::{Child, Command, Stdio},
};
const VERSION: &str = env!("CARGO_PKG_VERSION");
fn main() {
let ret = clparse::Arguments::parse_from_args().unwrap();
let config = ret.0;
// println!("{}", config);
loop {
// use the `>` character as the prompt
// need to explicitly flush this to ensure it prints before read_line
print!("{} ~> ", std::env::current_dir().unwrap().display());
stdout().flush().unwrap();
let mut input = String::new();
stdin().read_line(&mut input).unwrap();
print!("{}", input);
let mut in_qoute = false;
let mut building_command = String::new();
let mut command_chain: Vec<String> = vec![];
for x in input.chars() {
if x == '"' {
in_qoute = !in_qoute;
}
if x == '+' || x == '\n' {
if !in_qoute {
command_chain.push(building_command.trim().to_string());
building_command = String::new();
}
} else {
building_command.push(x);
}
}
for mut command in command_chain {
let abc = config.get("alias");
for x in abc.unwrap().as_table().unwrap() {
if command == *x.0 {
command = (*x.1).to_string();
command.remove(0);
command.pop();
}
}
println!("Command: {}", command);
}
}
}