Skip to content

[Feature request] Output color codes to preview command when using --ansi #4626

@mnalli

Description

@mnalli

Checklist

  • I have read through the manual page (man fzf)
  • I have searched through the existing issues
  • For bug reports, I have checked if the bug is reproducible in the latest version of fzf

Output of fzf --version

0.67.0 (2ab923f)

OS

  • Linux
  • macOS
  • Windows
  • Etc.

Shell

  • bash
  • zsh
  • fish

Problem / Steps to reproduce

I am working on an fzf-based shell snippet manager, now working on the batcat integration.

I was looking for a way to output color codes to the preview command when using --ansi flag.

# this command colors the filtering list, but not the output preview
bat --decorations=never --color=always ~/snippets.sh ~/paths.path | fzf --ansi --preview="echo {}"
Image
# this command shows color codes in the filtering list, but shows the correctly colored preview output
bat --decorations=never --color=always ~/snippets.sh ~/paths.path | fzf --preview="echo {}"
Image

Of course I could use another preview command, e.g. echo {} | bat -l bash, but this way I am forced to specify a language. The nice thing of using just a plain echo {} is that bat can just color its output based on file extension, e.g. .sh, .path.

Could we add a --ansi-preview option (or something like that) for this purpose?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions