Improve support for variable prompt in shell scripting (#428)

This commit is contained in:
Denis Isidoro 2020-10-15 15:44:56 -03:00 committed by GitHub
parent 648ebff1cd
commit 6dcbcfea54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 6 deletions

2
Cargo.lock generated
View file

@ -196,7 +196,7 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
[[package]]
name = "navi"
version = "2.12.2"
version = "2.13.0"
dependencies = [
"anyhow",
"directories-next",

View file

@ -1,6 +1,6 @@
[package]
name = "navi"
version = "2.12.2"
version = "2.13.0"
authors = ["Denis Isidoro <denis_isidoro@live.com>"]
edition = "2018"
description = "An interactive cheatsheet tool for the command-line"

View file

@ -10,7 +10,23 @@ navi --query "change branch" --best-match
**navi** will ask the user to fill all arguments needed.
If you want to set the `<branch>` beforehand in your script, you could then write:
If you want to set the `<branch>` beforehand in your script:
```sh
branch="master" navi --query "change branch" --best-match
```
- no interactive input will be shown
- the value for `<branch>` will be exactly the one passed as argument
If you want to filter some results for `<branch>`:
```sh
branch__query="master" navi --query "change branch" --best-match
```
- an interactive input will be shown, unless a single entry is autoselected
- the value for `<branch>` will be the one selected
If you want to select the best match for `<branch>`:
```sh
branch__best="master" navi --query "change branch" --best-match
```
- no interactive input will be shown
- the value for `<branch>` will be the one that best matches the one passed as argument

View file

@ -40,10 +40,10 @@ fn gen_core_finder_opts(config: &Config) -> Result<FinderOpts, Error> {
fn extract_from_selections(raw_snippet: &str, is_single: bool) -> Result<(&str, &str, &str, &str), Error> {
let mut lines = raw_snippet.split('\n');
let key = if !is_single {
lines.next().context("Key was promised but not present in `selections`")?
} else {
let key = if is_single {
"enter"
} else {
lines.next().context("Key was promised but not present in `selections`")?
};
let mut parts = lines.next().context("No more parts in `selections`")?.split(display::DELIMITER).skip(3);
@ -113,6 +113,13 @@ NAVIEOF
..opts.clone().unwrap_or_default()
};
opts.query = env::var(format!("{}__query", variable_name)).ok();
if let Ok(f) = env::var(format!("{}__best", variable_name)) {
opts.filter = Some(f);
opts.suggestion_type = SuggestionType::SingleSelection;
}
if opts.preview_window.is_none() {
opts.preview_window = Some(if extra_preview.is_none() {
format!("up:{}", variable_count + 3)