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

Fix bat colorization and robust config file detection #158

Merged
merged 4 commits into from
Sep 22, 2024

Conversation

suvayu
Copy link
Contributor

@suvayu suvayu commented Sep 18, 2024

  • Fix bat colorize when no --style/--theme is detected
  • Use bat --config-file for more robustness

Additional Remarks

re: config file issue: the location of the config file is platform dependent, it can also be set to a custom location by setting an environment variable. So instead of trying to guess, follow upstream recommendation

Without the check, when there are no --style/--theme flags (e.g. when
they are in the user config file), the `bat` command line was
constructed something like this:

  bat -l sh --style= --theme= --color=always --paging=never <file>

This led to the following error and failure to colorize:

  error: invalid value '' for '--style <components>': Unknown style, ''

  For more information, try '--help'.

Skip adding those flags when they are empty (not detected).
Instead of hard coded path in `$HOME/.config`, ask `bat` for the
correct path.  This is more robust since `bat` it is platform
independent.
@suvayu suvayu changed the title Fix bat colorization and more robust config file detection Fix bat colorization and robust config file detection Sep 18, 2024
lesspipe.sh Outdated Show resolved Hide resolved
wofr06 and others added 2 commits September 22, 2024 10:07
Changed the commit slightly to allow for the name batcat
Co-authored-by: Nobuyoshi Nakada <nobu.nakada@gmail.com>
@wofr06 wofr06 marked this pull request as draft September 22, 2024 08:25
@wofr06
Copy link
Owner

wofr06 commented Sep 22, 2024

Instead of bat as the name of the program please use $prog. At least in Ubuntu the program is called batcat

Copy link
Owner

@wofr06 wofr06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be ok now

@wofr06 wofr06 marked this pull request as ready for review September 22, 2024 14:49
@wofr06 wofr06 merged commit 535826a into wofr06:lesspipe Sep 22, 2024
1 check passed
@suvayu suvayu deleted the bat-colorize branch September 23, 2024 00:03
@suvayu
Copy link
Contributor Author

suvayu commented Sep 23, 2024

Thanks for reviewing and accepting the PR 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants