Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bat error] No such file or directory (os error 2) in fzf preview when used with ripgrep #3110

Open
thomastthai opened this issue Oct 19, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@thomastthai
Copy link

thomastthai commented Oct 19, 2024

What steps will reproduce the bug?

❯ cd ~/Documents/
❯ mkdir bat-error
❯ cd bat-error/
❯ touch a.txt b.txt c.txt
❯ echo "An apple a day keeps the doctor away." >> a.txt
❯ echo "The quick brown fox jumps over the lazy dog." >> b.txt
❯ echo "The five boxing wizards jump quickly at dawn" >> c.txt
❯ rg --glob '*.txt' "brown fox" | fzf --preview-window=top,wrap --preview 'bat --color=always "{}"'

What happens?

fzf's preview window shows:

[bat error]: ''b.txt:The quick brown fox jumps over the lazy dog.'': No such file or directory (os error 2)
Screenshot 2024-10-19 at 12 10 19 AM

...

What did you expect to happen instead?

For the preview window to show the filename and the matched line in the fzf preview window without the error.
...

How did you install bat?

homebrew


bat version and environment

]❯ bat --diagnostic

Software version

bat 0.24.0

Operating system

macOS 15.0.1 (Darwin 24.0.0)

Command-line

bat --diagnostic

Environment variables

SHELL=/opt/homebrew/bin/bash
PAGER=<not set>
LESS=<not set>
LANG=en_US.UTF-8
LC_ALL=<not set>
BAT_PAGER=<not set>
BAT_PAGING=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=/Users/thomas/.config
XDG_CACHE_HOME=/Users/thomas/.cache
COLORTERM=truecolor
NO_COLOR=<not set>
MANPAGER=<not set>

System Config file


Config file

# Set the theme to "TwoDark"
--theme="TwoDark"

# Show line numbers, Git modifications and file header (but no grid)
--style="numbers,changes,header"

# Use italic text on the terminal (not supported on all terminals)
--italic-text=always

# Use C++ syntax for Arduino .ino files
--map-syntax "*.ino:C++"

Custom assets metadata

bat_version: 0.24.0
creation_time:
  secs_since_epoch: 1729291942
  nanos_since_epoch: 656985000

Custom assets

  • metadata.yaml, 97 bytes
  • syntaxes.bin, 915557 bytes
  • themes.bin, 40606 bytes

Compile time information

  • Profile: release
  • Target triple: aarch64-apple-darwin
  • Family: unix
  • OS: macos
  • Architecture: aarch64
  • Pointer width: 64
  • Endian: little
  • CPU features: aes,crc,dit,dotprod,dpb,dpb2,fcma,fhm,flagm,fp16,frintts,jsconv,lor,lse,neon,paca,pacg,pan,pmuv3,ras,rcpc,rcpc2,rdm,sb,sha2,sha3,ssbs,vh
  • Host: aarch64-apple-darwin

Less version

> less --version
less 581.2 (POSIX regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less

Could this error be similar to #2628?

@thomastthai thomastthai added the bug Something isn't working label Oct 19, 2024
@LangLangBart
Copy link

By setting the --delimiter flag to :, and using the first field index expression {1}, the file name will be correctly passed to bat. Quoting the placeholder is not needed, fzf does it for you.

rg --glob '*.txt' "brown fox" |
  fzf --delimiter ":" --preview-window=top,wrap --preview 'bat --color=always {1}'

PS: fzf has extensive documentation1 on an interactive rg function with bat used to preview the file.

Footnotes

  1. fzf/ADVANCED.md at master · junegunn/fzf · GitHub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants