diff --git a/Cargo.lock b/Cargo.lock index f356d0e..83252cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,7 +196,7 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "navi" -version = "2.12.2" +version = "2.13.0" dependencies = [ "anyhow", "directories-next", diff --git a/Cargo.toml b/Cargo.toml index d58158c..b1c4b57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "navi" -version = "2.12.2" +version = "2.13.0" authors = ["Denis Isidoro "] edition = "2018" description = "An interactive cheatsheet tool for the command-line" diff --git a/docs/shell_scripting.md b/docs/shell_scripting.md index 8fc7be7..edcca0c 100644 --- a/docs/shell_scripting.md +++ b/docs/shell_scripting.md @@ -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 `` beforehand in your script, you could then write: +If you want to set the `` beforehand in your script: ```sh branch="master" navi --query "change branch" --best-match ``` +- no interactive input will be shown +- the value for `` will be exactly the one passed as argument + +If you want to filter some results for ``: +```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 `` will be the one selected + +If you want to select the best match for ``: +```sh +branch__best="master" navi --query "change branch" --best-match +``` +- no interactive input will be shown +- the value for `` will be the one that best matches the one passed as argument \ No newline at end of file diff --git a/src/cmds/core.rs b/src/cmds/core.rs index 4c6ffee..8989f83 100644 --- a/src/cmds/core.rs +++ b/src/cmds/core.rs @@ -40,10 +40,10 @@ fn gen_core_finder_opts(config: &Config) -> Result { 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)