$ echo '#' > /tmp/test.yml
$ bat /tmp/test.yml
Bat is then stuck using 100% of the CPU.
It is is only reproducible if file has the yml extension.
Strace shows bat is stuck doing calls like mremap(0x7f3c29518000, 2887680, 5771264, MREMAP_MAYMOVE) calls with size being doubled at each call.
~EDIT: Actually it is also reproducible if the file is empty.~
Thank you for reporting this.
I can not reproduce this. Which version of bat are you using and which system are you on?
Could you please post the output of
set -x
bat --version
bat --config-file
bat --cache-dir
less --version
bat "$(bat --config-file)"
ls "$(bat --cache-dir)"
set +x
echo "BAT_PAGER = '$BAT_PAGER'"
echo "BAT_CONFIG_PATH = '$BAT_CONFIG_PATH'"
echo "BAT_STYLE = '$BAT_STYLE'"
echo "BAT_THEME = '$BAT_THEME'"
echo "BAT_TABS = '$BAT_TABS'"
echo "PAGER = '$PAGER'"
echo "LESS = '$LESS'"
Well now I can only reproduce if the file has a '#' char, not if the file is empty, I probably tested the wrong file last time.
System is Arch Linux, obviously up to date.
I have shell aliases, for bat, cat, and less, so i use command for clarity:
$ command bat --version
bat 0.12.1
$ command bat --config-file
/home/desbma/.config/bat/config
$ command bat --cache-dir
/home/desbma/.cache/bat
$ command less --version
less 551 (PCRE regular expressions)
Copyright (C) 1984-2019 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: http://www.greenwoodsoftware.com/less
set +x
echo "BAT_PAGER = '$BAT_PAGER'"
echo "BAT_CONFIG_PATH = '$BAT_CONFIG_PATH'"
echo "BAT_STYLE = '$BAT_STYLE'"
echo "BAT_THEME = '$BAT_THEME'"
echo "BAT_TABS = '$BAT_TABS'"
echo "PAGER = '$PAGER'"
echo "LESS = '$LESS'"
BAT_PAGER = ''
BAT_CONFIG_PATH = ''
BAT_STYLE = ''
BAT_THEME = 'Solarized (dark)'
BAT_TABS = ''
PAGER = ''
LESS = ''
it is also reproducible if I unset the BAT_THEME env var.
FYI this is not reproducible on another machine with Debian Sid and bat 0.12.1.
I can also reproduce it on Arch Linux, with cat rebuild from this repository:
v0.12.1 tagThank you for the update. Could you please also post the output of
bat "$(bat --config-file)"
ls "$(bat --cache-dir)"
as suggested above? I could imagine that you have a broken syntax-cache (maybe from an old verison of bat). In this case, you could probably fix the error by running bat cache --clear.
Sorry I misssed these two commands.
I don't have any config file. For cache files:
$ ls "$(bat --cache-dir)"
syntaxes.bin themes.bin
Thanks bat cache --clear did fix it.
Maybe bat should have some mechanism to detect stale cache files, and warn or rebuild them?
Thanks
bat cache --cleardid fix it.
:+1: Thank you for the feedback.
Maybe
batshould have some mechanism to detect stale cache files, and warn or rebuild them?
Not sure if that's possible. It can depend on whether or not the original syntax files from which the cache has been built were problematic or not.
I have added:
[ "$(command -v bat)" -ot ~/.cache/bat/syntaxes.bin ] && bat cache -b
In my shell files to rebuild the cache if it's older than the bat binary.
In my experience this is needed to avoid this issue and many others like for example missing syntax coloring for man that only appeared in newer bat versions.
@desbma Thank you very much for your feedback. I have just opened #882 which attempts to solve this problem in the future.