Add is-interactive and is-login to NuVariable and allow running scripts with -i (#8306)

Add two rows in `$nu`, `$nu.is-interactive` and `$nu.is-login`, which
are true when nu is run in interactive and login mode respectively.

The `-i` flag now behaves a bit more like that of bash's, where the any
provided command or file is run without REPL but in "interactive mode".
This should entail sourcing interactive-mode config files, but since we
are planning on overhauling the config system soon, I'm holding off on
that. For now, all `-i` does is set `$nu.is-interactive` to be true.

About testing, I can't seem to find where cli-args get tested, so I
haven't written any new tests for this. Also I don't think there are any
docs that need updating. However if I'm wrong please tell me.
This commit is contained in:
StevenDoesStuffs
2023-03-08 20:59:33 -06:00
committed by GitHub
parent d31a51e3bc
commit 7e949595bd
5 changed files with 80 additions and 6 deletions

View File

@ -145,6 +145,8 @@ pub struct EngineState {
// If Nushell was started, e.g., with `nu spam.nu`, the file's parent is stored here
pub currently_parsed_cwd: Option<PathBuf>,
pub regex_cache: Arc<Mutex<LruCache<String, Regex>>>,
pub is_interactive: bool,
pub is_login: bool,
}
// The max number of compiled regexes to keep around in a LRU cache, arbitrarily chosen
@ -195,6 +197,8 @@ impl EngineState {
regex_cache: Arc::new(Mutex::new(LruCache::new(
NonZeroUsize::new(REGEX_CACHE_SIZE).expect("tried to create cache of size zero"),
))),
is_interactive: false,
is_login: false,
}
}