From 0bf2c601c3fb075b11148900fe29a83024e36548 Mon Sep 17 00:00:00 2001 From: Justine Pelletreau Date: Tue, 21 Feb 2023 17:02:10 +0100 Subject: [PATCH] Added an init line in sqishrc --- README.md | 1 - src/lib.rs | 9 +++++++-- src/shell/config.rs | 5 ++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 638201e..4e55c90 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ Rust Shell. This is an attempt to create a simple shell in Rust, because why not TODO: * git commit -m "message" does not work -* Startup script section in sqishrc ## sqishrc (Config) See the included sqishrc file included, and copy it as ~/.sqishrc diff --git a/src/lib.rs b/src/lib.rs index 07c2b7a..70fe03e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -342,6 +342,7 @@ pub mod shell { promptline_base: String::from("!$HISTNUMBER_$COLORGREEN_[$USER_@$HOSTNAME_]$COLORRESET_ "), aliases: HashMap::new(), hotkeys: HashMap::new(), + init: String::new(), }; let ret_line = format!("Could not build conf, got {}\ \r\nUsing default promptline", e); @@ -351,10 +352,14 @@ pub mod shell { }; &conf.update_prompt(get_curr_history_number()); - //Initialize - write!(stdout, "\r\n SquiShell (sqish)--- \r\n{}", conf.promptline); + //Initializing + write!(stdout, "\r\n ---Sqish initializing...--- \r\n{}", conf.promptline); stdout.flush(); + if conf.init != String::from("") { + run_cmd(&mut String::from(&conf.init), &mut current_number, &mut conf, &mut stdout); + } + for c in stdin.keys() { let k = c.unwrap(); match k { diff --git a/src/shell/config.rs b/src/shell/config.rs index ea33f90..85a8e3c 100644 --- a/src/shell/config.rs +++ b/src/shell/config.rs @@ -15,6 +15,7 @@ pub struct SqishConf { pub promptline_base: String, pub aliases: HashMap, pub hotkeys: HashMap, + pub init: String, } impl SqishConf { @@ -42,7 +43,8 @@ impl SqishConf { }; let sqishrc = &sqishrc[0]; - let out_str = String::from(sqishrc["prompt"].as_str().unwrap()); + let out_str = String::from(sqishrc["prompt"].as_str().unwrap_or("$ ")); + let startup = String::from(sqishrc["init"].as_str().unwrap_or("")); //Loading hotkeys and aliases from yaml //They can be empty, be careful... @@ -57,6 +59,7 @@ impl SqishConf { promptline_base: out_str, aliases: aliases, hotkeys: hotkeys, + init: startup, }; out_conf.handle_rgb();