Can now cd to a directory containing spaces; entering a command reset

the history callback counter. Changed the exit prompt to be friendlier.
This commit is contained in:
Justine 2023-02-20 18:34:42 +01:00
parent 981cebea5b
commit 30cb3f9887
2 changed files with 13 additions and 5 deletions

View File

@ -5,7 +5,6 @@ TODO:
* Aliases don't currently handle arguments. My alias "vless" does not work with "vless lib.rs"
* A shortcut / implemented command to show all Hotkeys
* git commit -m "message" does not work
* Can't cd to a directory containing spaces in its name
* Startup script section in sqishrc
## sqishrc (Config)

View File

@ -47,9 +47,17 @@ pub mod shell {
match command {
"cd" => {
let args = args.collect::<Vec<&str>>();
let homedir = dirs::home_dir().unwrap().into_os_string().into_string().unwrap();
let new_dir = args.peekable().peek().map_or(homedir.as_str(), |x| *x);
let root = Path::new(new_dir);
//let new_dir = args.peekable().peek().map_or(homedir.as_str(), |x| *x);
let mut new_dir = String::new();
if args.len() > 0 {
*&mut new_dir = args.join(" ");
} else {
*&mut new_dir = String::from(homedir.as_str());
}
let root = Path::new(&new_dir);
if let Err(e) = env::set_current_dir(&root) {
eprintln!(" Err: {}", e);
} else {
@ -237,7 +245,7 @@ pub mod shell {
stdout.flush();
*current_number += 1;
} else if mycommand == &String::from("exit") {
write!(stdout, "\r\n Sayonara \r\n");
write!(stdout, "\r\nThanks for using Sqish!\r\nSayonara \r\n");
RawTerminal::suspend_raw_mode(&stdout);
std::process::exit(0);
} else {
@ -342,6 +350,7 @@ pub mod shell {
stdout.flush();
}
Key::Char('\n') => {
current_number = get_curr_history_number();
current_pos = 0;
max_pos = 0;
run_cmd(&mut mycommand,
@ -352,7 +361,7 @@ pub mod shell {
Key::Ctrl('q'|'d') => {
RawTerminal::suspend_raw_mode(&stdout);
writeln!(stdout, "\r\n Sayonara \r\n");
writeln!(stdout, "\r\nThanks for using Sqish !\r\nSayonara \r\n");
break;
},