aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-10-11 14:11:40 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-10-11 14:11:40 +0300
commit8b2814f254ef63d806bb5435b3d193458cfd4537 (patch)
tree1f792da133800d23db3c43008b46dcb74214df4a /src/main.rs
parentInitial commit (diff)
downloadrshell-8b2814f254ef63d806bb5435b3d193458cfd4537.tar.xz
Make Prompt more const
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index a4f3c25..0581b13 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,12 +5,19 @@ mod builtins;
mod prompt;
fn main() {
- println!("rshell motd");
+ match std::fs::read_to_string("/etc/motd") {
+ Ok(motd) => println!("{}", motd),
+ Err(_) => {},
+ }
- let mut prompt = prompt::Prompt::new();
+ let prompt = prompt::Prompt::new();
+ let mut cwd = match std::env::current_dir() {
+ Ok(p) => p,
+ Err(e) => panic!(e),
+ };
loop {
- prompt.print();
+ prompt.print(&cwd);
let mut input = String::new();
match std::io::stdin().read_line(&mut input) {
@@ -36,7 +43,7 @@ fn main() {
match command {
"cd" => {
- prompt.pwd = builtins::cd(args);
+ cwd = builtins::cd(args);
previous_command = None;
}
"exit" => return,
@@ -70,7 +77,11 @@ fn main() {
if let Some(mut final_command) = previous_command {
match final_command.wait() {
Ok(ret) => match ret.code() {
- Some(code) => println!("exit code [{}]", code),
+ Some(code) => {
+ if cfg!(debug_assertions) {
+ println!("exit code [{}]", code);
+ }
+ },
None => println!("Process termed by signal"),
},
Err(e) => eprintln!("error waiting on final command: {}", e),