2022-12-03 12:15:03 -06:00
|
|
|
use std::{
|
|
|
|
env,
|
|
|
|
io::{stdin, stdout, Read, Write},
|
|
|
|
path::Path,
|
|
|
|
process::{Child, Command, Stdio},
|
|
|
|
};
|
|
|
|
|
2022-12-05 04:14:26 -06:00
|
|
|
use versioning::Version;
|
|
|
|
|
|
|
|
pub const VERSION: Version = Version::new(0, 1, 0);
|
2022-12-03 12:15:03 -06:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-05 04:14:26 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn sanity_check_version() {
|
|
|
|
let cargo_version = env!("CARGO_PKG_VERSION");
|
|
|
|
let str_version = format!("{}", VERSION);
|
|
|
|
assert_eq!(str_version, cargo_version);
|
|
|
|
}
|