Allow fzf overrides after --- (#505)

Fixes #317
This commit is contained in:
Denis Isidoro 2021-04-15 09:23:35 -03:00 committed by GitHub
parent 5acdb2a4b2
commit 1c9ffde3ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 6 deletions

View file

@ -61,9 +61,10 @@ $ mapped: echo 'false true' | tr ' ' '\n' --- --map "grep -q t && echo 1 || echo
```
The supported parameters are:
- `--prevent-extra` *(experimental)*: limits the user to select one of the suggestions;
- `--column <number>`: extracts a single column from the selected result;
- `--map <bash_code>` *(experimental)*: applies a map function to the selected variable value;
- `--prevent-extra` *(experimental)*: limits the user to select one of the suggestions;
- `--fzf-overrides <arg>` *(experimental)*: applies arbitrary `fzf` overrides;
In addition, it's possible to forward the following parameters to `fzf`:
- `--multi`;

View file

@ -30,7 +30,7 @@ fn prompt_finder(
let mut extra_preview = None;
let (suggestions, opts) = if let Some(s) = suggestion {
let (suggestions, initial_opts) = if let Some(s) = suggestion {
let (suggestion_command, suggestion_opts) = s;
if let Some(sopts) = suggestion_opts {
@ -68,8 +68,18 @@ fn prompt_finder(
('\n'.to_string(), &None)
};
let overrides = {
let mut o = config.fzf_overrides.clone();
if let Some(io) = initial_opts {
if io.overrides.is_some() {
o = io.overrides.clone()
}
}
o
};
let mut opts = FinderOpts {
overrides: config.fzf_overrides_var.clone(),
overrides,
preview: Some(format!(
r#"{prefix}navi preview-var "$(cat <<NAVIEOF
{{+}}
@ -83,7 +93,7 @@ NAVIEOF
name = variable_name,
extra = extra_preview.clone().unwrap_or_default()
)),
..opts.clone().unwrap_or_default()
..initial_opts.clone().unwrap_or_default()
};
opts.query = env_var::get(format!("{}__query", variable_name)).ok();

View file

@ -59,7 +59,7 @@ fn parse_opts(text: &str) -> Result<FinderOpts, Error> {
"--preview" => opts.preview = Some(value.to_string()),
"--preview-window" => opts.preview_window = Some(value.to_string()),
"--header" => opts.header = Some(value.to_string()),
"--overrides" => opts.overrides = Some(value.to_string()),
"--fzf-overrides" => opts.overrides = Some(value.to_string()),
_ => (),
}
Ok(())

View file

@ -56,11 +56,14 @@ echo description one character
# map can be used to expand into multiple arguments
for l in <phrases>; do echo "line: $l"; done
# x
echo <with_overrides>
# Concatenate pdf files
files=($(echo "<files>"))
echo pdftk "${files[@]:-}" cat output <pdf_output>
$ files: echo 'file1.pdf file2.pdf file3.pdf' | tr ' ' '\n' --- --multi --overrides '--tac'
$ files: echo 'file1.pdf file2.pdf file3.pdf' | tr ' ' '\n' --- --multi --fzf-overrides '--tac'
$ x: echo '1 2 3' | tr ' ' '\n'
$ y: echo 'a b c' | tr ' ' '\n'
$ z: echo 'foo bar' | tr ' ' '\n'
@ -73,6 +76,7 @@ $ examples: echo -e 'foo bar\nlorem ipsum\ndolor sit' --- --multi
$ multiword: echo -e 'foo bar\nlorem ipsum\ndolor sit\nbaz'i
$ file: ls . --- --preview 'cat {}' --preview-window 'right:50%'
$ phrases: echo -e "foo bar\nlorem ipsum\ndolor sit" --- --multi --map "navi fn map::expand"
$ with_overrides: echo -e "foo bar\nlorem ipsum\ndolor sit" --- --fzf-overrides "--margin=15% --bind=ctrl-u:replace-query"
# this should be displayed
echo hi