Comments (17)
It's been almost two years, but I finally found the time to implement this. See #940 for details and screenshot.
from bat.
@bendem Could you elaborate what that means?
I mean that git supports highlighting inside of lines, which I don't think bat
does yet. That would be an awesome feature to have.
from bat.
I think that at this point a single flag or subcommand would be appropriate -- the assumption with a libgit2
-based diff is that you're operating inside of a Git repository.
Requirements I'm confident should be part of this
This flag/subcommand (hereafter referred to as diff
, which is definitely subject to bikeshedding):
- will fail the entire command if not inside of a Git repo
- should take a reasonable subset of options that map to common
git diff
invocations; some example invocations might be:bat diff
would display all unstaged changes, minus untracked files (a lagit diff
)bat diff cached
would display all staged changes (a lagit diff --cached
)- Alternative invocations for this use case could look like
bat --diff --cached
- Alternative invocations for this use case could look like
Unresolved questions
-
Should this be a subcommand or a flag?
- Flags would be unambiguous, but a subcommand might look more ergonomic (
git
-esque, in this case). - If a subcommand is desired, then maybe the following design would work:
bat print
or some similar subcommand would be the default when only file paths are provided. For instance, given the following file structure:foo
:$ tree . ├── diff ├── foo.txt └── print
...then:
bat foo.txt
would be equivalent to today's functionality, inferred to bebat [print] foo.txt
.bat print
would be ambiguous and return an error reporting that a file and a subcommand exist with that name. This can be resolved by usingbat print print
. This case could also just print a warning tostderr
, since in this case the intent to print a file is NOT ambiguous.bat diff
would likewise report an ambiguity, as withprint
. This would have to be a hard error, and resolved with eitherbat print diff
orbat diff --
, depending on the intended subcommand.
- Alternatively,
bat <file>
shorthand could simply be removed and get rid of the ambiguous cases in the above design.
- Flags would be unambiguous, but a subcommand might look more ergonomic (
-
Should
bat diff
be a filter of the format we get frombat print
, or more of adiff
pager?- The difference is that a filter would only show diff number column marks, while a
diff
pager would actually show the deleted/added lines a lagit diff
. - IIUC, treating this flag as a filter more closely matches the spirit of the
--context
idea in the issue you linked.
- The difference is that a filter would only show diff number column marks, while a
from bat.
Your first bullet point sounds like a waaay-streamlined version of what I just proposed. I would definitely choose that over what I suggested. :)
I would also vote for only doing the first bullet point as a first iteration -- I'd be happy with that, and I don't know how straightforward it would be to highlight things without the full file.
from bat.
@ErichDonGubler: Are you aware of https://github.com/dandavison/delta, which implements a pager for git diffs?
from bat.
@sharkdp: Not enough emojis to express my excitement. :)
from bat.
Thank you for the feedback!
Nice idea! I actually was on a similar track here: #12 (see --context
option).
Would you be open to a PR
Definitely! However, maybe it would be worth to first discuss some details here in this ticket?
For example, how would the command line interface (subcommand, option/flag) for that feature look like?
I'm not sure if this should be a special way to process diff/patch files or just integrated with libgit2 directly -- the latter is probably easier, since you're already using libgit2 as a dependency.
Yes, libgit2 sounds like the better option to me.
from bat.
@ErichDonGubler Thank you very much for writing this up! It might take me a few days before I get back to you on this.
from bat.
What I don't really like about adding a diff
subcommand (or option) is that we open up a completely new field with that functionality. While we are not truly following the UNIX "do one thing and do it well" philosophy with bat
, it is mainly a program that is intended to display file contents.
So here is a slightly different proposal that I would like to discuss:
- Add a
--diff-context=<lines>
option (didn't come up with a better name for now), which, when enabled, would only show<lines>
lines of context around modified parts of the specified files (the default would be "--diff-context=infinite
"). - Write a tool to provide
git diff
-like functionality. This could be as simple asgit diff --name-only | xargs bat --diff-context=3
Edit: changed --hunk-context
to --diff-context
from bat.
Since we are speaking about this and it's being considered, is there any plan for also supporting diff-highlight type of highlighting?
from bat.
@bendem Could you elaborate what that means?
from bat.
I think my proposal above should be rather straightforward to implement.
I think we should first (possibly in a separate PR) update the --line-range
option to be accepted multiple times.
In a second step, we would then use the Git modifications and the value given in the --diff-context
option to generate a list of line-ranges that could be processed by the already existing line-range functionality
from bat.
@bendem Thank you for your feedback. This is not really related to this ticket. I don't currently plan to implement inline-diffs and I think that would be quite a substantial feature. If you think this should be discussed, please open a new ticket.
from bat.
I think we should first (possibly in a separate PR) update the
--line-range
option to be accepted multiple times.
That first part has been implemented in #368
from bat.
We are aware of delta
. That's why we added it to the README.
from bat.
@sharkdp can you publish a new release?
from bat.
Released in v0.15.0.
from bat.
Related Issues (20)
- Documentation Enhancement: Include Information on BAT_CONFIG_DIR Environment Variable
- Couldn't find the man page (or build dir) after install from source HOT 2
- Allow turning on and off styles, relative to current settings HOT 2
- Dependabot partially broken or disabled HOT 1
- Zsh tab complete with -l flag is broken
- Syntax request: typst
- Display Garbled on Windows Terminal HOT 2
- Multiple line selection
- `bat` silently quits, rather than reporting an error, if `less` is missing HOT 7
- Detect paths and highlight them if missing HOT 4
- `'rendering': Access is denied.` when trying to pipe output using pwsh HOT 3
- Whether to consider internationalization? HOT 1
- Bat outputs weird characters HOT 6
- Allow bat to replace variables on text HOT 2
- [Feature request] Add setting to enable maximum column for TSV hyghlighting HOT 2
- possibility to suppress output if stdin is empty and set header manually HOT 5
- Option to omit binary content even when writing to a file
- Syntax request: RDF 🐢 Turtle & SPARQL (*.ttl, *.ttls, etc.)
- compatibility issue with cat while piping in scripts
- Gherkin support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bat.