Conditional preview configuration based on current line #3884
-
Hi, I've been trying to put together a file browser using fzf. I want to run search commands against both filepaths and against the file contents. For example, if I search for DatabaseHandle, I'd like to see line results for both /path/to/DatabaseHandle.js and code references like I have that working. But now I'd like to show file previews, and I'm getting stuck on the behavior. And I want to say, "if {2} exists, highlight the line using the value from {2}. If it's null, highlight line one (or don't highlight any line, which serves the same purpose)." I'd really like to be able to either: Nothing seemed like an obvious way to maybe-include a given token that might-not-exist. I've scoured the docs/issues/discussions and started trying to write a custom preview function to parse {}, but I think I'm getting tripped up parsing the quoted strings (and not having an easy time debugging when I need to fetch the tokens at runtime and somehow debug them by viewing variables in a preview window). So I'd love any tips for how I should do this right! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Would this serve as a solution ? cat <<'EOF' | fzf --delimiter ':' --preview 'line={2}; bat --color=always --highlight-line ${line:-1} {1}'
/usr/share/misc/ascii:8
/usr/share/misc/ascii
/usr/share/misc/birthtoken
/usr/share/misc/birthtoken:2
EOF |
Beta Was this translation helpful? Give feedback.
Would this serve as a solution ?