Skip to content

Commit

Permalink
Disable preview-window for variable suggestions (#343)
Browse files Browse the repository at this point in the history
Fixes #338 

Reopens #320
  • Loading branch information
denisidoro authored Apr 13, 2020
1 parent 3188a76 commit 4853a67
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/flows/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,20 @@ fn extract_from_selections(raw_snippet: &str, contains_key: bool) -> (&str, &str
(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(
variable_name: &str,
config: &Config,
suggestion: &Suggestion,
values: &HashMap<String, String>,
snippet: String,
_snippet: String,
) -> Result<String, Error> {
let mut vars_cmd = String::from("");
for (key, value) in values.iter() {
Expand All @@ -100,17 +108,13 @@ fn prompt_with_suggestions(
)
.context("Suggestions are invalid utf8")?;

let mut opts = suggestion_opts.clone().unwrap_or_default();
if opts.preview.is_none() {
opts.preview = Some(format!(
"echo '{}' | sed 's/<{}>/{{}}/g'",
snippet.replace('\'', "\""),
variable_name
));
let opts = suggestion_opts.clone().unwrap_or_default();
/* if opts.preview.is_none() {
opts.preview = gen_opts_preview(&snippet, &variable_name);
}
if opts.preview_window.is_none() {
opts.preview_window = Some("up:1".to_string());
}
} */
let opts = FinderOpts {
autoselect: !config.no_autoselect,
overrides: config.fzf_overrides_var.clone(),
Expand All @@ -134,17 +138,13 @@ fn prompt_with_suggestions(
fn prompt_without_suggestions(
variable_name: &str,
config: &Config,
snippet: String,
_snippet: String,
) -> Result<String, Error> {
let opts = FinderOpts {
autoselect: false,
prompt: Some(display::variable_prompt(variable_name)),
suggestion_type: SuggestionType::Disabled,
preview: Some(format!(
"echo '{}' | sed 's/<{}>/{{}}/g'",
snippet.replace('\'', "\""),
variable_name
)),
// preview: gen_opts_preview(&snippet, &variable_name),
preview_window: Some("up:1".to_string()),
..Default::default()
};
Expand Down
8 changes: 8 additions & 0 deletions tests/cheats/more_cases.cheat
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ echo description space
#
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'
$ y: echo 'a b c' | tr ' ' '\n'
$ z: echo 'foo bar' | tr ' ' '\n'
Expand Down

0 comments on commit 4853a67

Please sign in to comment.