Disable preview-window for variable suggestions (#343)

Fixes #338 

Reopens #320
This commit is contained in:
Denis Isidoro 2020-04-13 14:27:05 -03:00 committed by GitHub
parent 3188a76759
commit 4853a6718c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 15 deletions

View file

@ -71,12 +71,20 @@ fn extract_from_selections(raw_snippet: &str, contains_key: bool) -> (&str, &str
(key, tags, snippet) (key, tags, snippet)
} }
/* fn gen_opts_preview(snippet: &str, variable_name: &str) -> Option<String> {
Some(format!(
r#"query="{{}}"; [[ "${{#query:-}}" -lt 3 ]] && query="{{q}}"; query="${{query:1:${{#query}}-2}}"; query="$(echo "$query" | sed 's|/|\\/|g')"; echo "{}" | sed "s/<{}>/${{query}}/g" || echo 'Unable to generate command preview'"#,
snippet.replace('"', "\\\""),
variable_name
))
} */
fn prompt_with_suggestions( fn prompt_with_suggestions(
variable_name: &str, variable_name: &str,
config: &Config, config: &Config,
suggestion: &Suggestion, suggestion: &Suggestion,
values: &HashMap<String, String>, values: &HashMap<String, String>,
snippet: String, _snippet: String,
) -> Result<String, Error> { ) -> Result<String, Error> {
let mut vars_cmd = String::from(""); let mut vars_cmd = String::from("");
for (key, value) in values.iter() { for (key, value) in values.iter() {
@ -100,17 +108,13 @@ fn prompt_with_suggestions(
) )
.context("Suggestions are invalid utf8")?; .context("Suggestions are invalid utf8")?;
let mut opts = suggestion_opts.clone().unwrap_or_default(); let opts = suggestion_opts.clone().unwrap_or_default();
if opts.preview.is_none() { /* if opts.preview.is_none() {
opts.preview = Some(format!( opts.preview = gen_opts_preview(&snippet, &variable_name);
"echo '{}' | sed 's/<{}>/{{}}/g'",
snippet.replace('\'', "\""),
variable_name
));
} }
if opts.preview_window.is_none() { if opts.preview_window.is_none() {
opts.preview_window = Some("up:1".to_string()); opts.preview_window = Some("up:1".to_string());
} } */
let opts = FinderOpts { let opts = FinderOpts {
autoselect: !config.no_autoselect, autoselect: !config.no_autoselect,
overrides: config.fzf_overrides_var.clone(), overrides: config.fzf_overrides_var.clone(),
@ -134,17 +138,13 @@ fn prompt_with_suggestions(
fn prompt_without_suggestions( fn prompt_without_suggestions(
variable_name: &str, variable_name: &str,
config: &Config, config: &Config,
snippet: String, _snippet: String,
) -> Result<String, Error> { ) -> Result<String, Error> {
let opts = FinderOpts { let opts = FinderOpts {
autoselect: false, autoselect: false,
prompt: Some(display::variable_prompt(variable_name)), prompt: Some(display::variable_prompt(variable_name)),
suggestion_type: SuggestionType::Disabled, suggestion_type: SuggestionType::Disabled,
preview: Some(format!( // preview: gen_opts_preview(&snippet, &variable_name),
"echo '{}' | sed 's/<{}>/{{}}/g'",
snippet.replace('\'', "\""),
variable_name
)),
preview_window: Some("up:1".to_string()), preview_window: Some("up:1".to_string()),
..Default::default() ..Default::default()
}; };

View file

@ -50,6 +50,14 @@ echo description space
# #
echo description blank echo description blank
# x
echo description one character
# 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'
$ x: echo '1 2 3' | tr ' ' '\n' $ x: echo '1 2 3' | tr ' ' '\n'
$ y: echo 'a b c' | tr ' ' '\n' $ y: echo 'a b c' | tr ' ' '\n'
$ z: echo 'foo bar' | tr ' ' '\n' $ z: echo 'foo bar' | tr ' ' '\n'