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

Show headers only when multiple files are passed #1311

Open
solson opened this issue Oct 12, 2020 · 6 comments
Open

Show headers only when multiple files are passed #1311

solson opened this issue Oct 12, 2020 · 6 comments
Labels
feature-request New feature or request

Comments

@solson
Copy link

solson commented Oct 12, 2020

Sorry if this has already been asked, but I couldn't find it.

Could it be made possible to configure bat to show headers (--style=header) only when more than one file is passed? I like to keep my --style quite minimal, and when viewing a single file, the filename is usually just extra noise to me, but with multiple files it's practically a necessity. Thanks!

@solson solson added the feature-request New feature or request label Oct 12, 2020
@sharkdp
Copy link
Owner

sharkdp commented Oct 14, 2020

Thank you for the feedback.

Originally, I had some plans to add more meta information to the header (like the detected syntax, the Git status of the file, …).

If we are going to leave this at the file name only, I agree that it's not very useful for a single file. It would only make sense for consistency.

@sharkdp
Copy link
Owner

sharkdp commented Jan 2, 2021

We've decided in #1395 that we don't want to add a new command line option for this. There might be another way (by specifying a new --style switch), but I'm inclined to close this as "won't do".

@solson
Copy link
Author

solson commented May 20, 2021

I wouldn't mind this much if I could define a shell alias that passes --style=numbers for the single-file case and --style=header,numbers for the multi-file case, but the problem is I'd have to effectively reimplement bat's flag parsing to count the number of inputs, or else accept being inaccurate in some cases. Even just ignoring arguments starting with - for the count would be relatively messy.

Can you think of any other way to support this cleanly?

@solson
Copy link
Author

solson commented May 20, 2021

I suppose I could be happy enough with two separate aliases, one doing bat --style=header,numbers and the other doing bat --style=numbers, but then I have to mention my "default" style in multiple places. A single alias would be ideal, though, so I can never forget and have to rerun with the other alias.

@sharkdp
Copy link
Owner

sharkdp commented Jul 25, 2021

Okay, let's try to implement this. We need to discuss the design, but maybe something like this could work:

  • Add a new single-file-header style component
  • Change the meaning of header to mean: only show headers if there are multiple files
  • Set the default style to header,single-file-header,….

Note: I haven't completely thought this through. Let's please discuss all implications of this before implementing it.

@lilyball
Copy link

I really want this. I feel like the best solution here is not to add new style components, but instead to just add a new flag --single-file-style=… that lets me override the style for single files, and if not specified it will use the --style config.

The question here is whether BAT_STYLE would affect this flag if it's not at the default. If BAT_STYLE is specified for a single invocation of bat then it should, if it's just set generally in the environment then it probably shouldn't, and I'm not sure which is more common.

Or maybe we can be a little more subtle and do a --multi-file-style= flag instead, with a new style component inherit that means "inherit the --style. With this approach the default is just --multi-file-style=inherit. And the reason for switching to multi-file instead of single-file is so we can then write e.g. --multi-file-style=inherit,header to add the header to the existing style. And with this approach BAT_STYLE will obviously just affect --style.

I do think conceptually a --single-file-style makes a bit more sense than a --multi-file-style, but since the common use-case here is "show a header for multiple files", the --single-file-style approach is harder to use.

AdamVig added a commit to AdamVig/dotfiles that referenced this issue May 3, 2024
- Omit line numbers by default
- Show headers
The header will be visible even when only one file is viewed due to
sharkdp/bat#1311.
- Move pager settings from alias into bat config file
- Remove `bp` alias now that line numbers are hidden by default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants