From 9c62bb646d45cc928057b0880017078cd5aaec85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Mon, 30 Sep 2024 17:06:35 -0600 Subject: [PATCH] Implement --norc option to skip sourcing .shellrc --- crates/shell/src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index dda81ef..0556b26 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -24,6 +24,10 @@ struct Options { #[clap(long)] interact: bool, + /// Do not source ~/.shellrc on startup + #[clap(long)] + norc: bool, + #[clap(short, long)] debug: bool, } @@ -34,7 +38,7 @@ fn init_state() -> ShellState { ShellState::new(env_vars, &cwd, commands::get_commands()) } -async fn interactive(state: Option) -> miette::Result<()> { +async fn interactive(state: Option, norc: bool) -> miette::Result<()> { let config = Config::builder() .history_ignore_space(true) .completion_type(CompletionType::List) @@ -66,7 +70,7 @@ async fn interactive(state: Option) -> miette::Result<()> { // Load ~/.shellrc let shellrc_file: PathBuf = [home.as_path(), Path::new(".shellrc")].iter().collect(); - if Path::new(shellrc_file.as_path()).exists() { + if !norc && Path::new(shellrc_file.as_path()).exists() { let line = "source '".to_owned() + shellrc_file.to_str().unwrap() + "'"; let prev_exit_code = execute(&line, &mut state) .await @@ -168,10 +172,10 @@ async fn main() -> miette::Result<()> { } execute(&script_text, &mut state).await?; if options.interact { - interactive(Some(state)).await?; + interactive(Some(state), options.norc).await?; } } else { - interactive(None).await?; + interactive(None, options.norc).await?; } Ok(())