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

Is it possible to show the file path in the hunk header? #309

Closed
infokiller opened this issue Sep 2, 2020 · 10 comments · Fixed by #453 or #470
Closed

Is it possible to show the file path in the hunk header? #309

infokiller opened this issue Sep 2, 2020 · 10 comments · Fixed by #453 or #470

Comments

@infokiller
Copy link

Hi,

Right now, the hunk header only shows the line number. diff-so-fancy also shows the file path, which I like because it gives me better orientation in a large diff (although it can be redundant with the commit/file box).
Is it possible to emulate this in delta?

Thanks!

@dandavison
Copy link
Owner

Hi @infokiller, that's very interesting, I didn't know (or had forgotten; I used d-s-f for many years) that diff-so-fancy did that. I think I might like that also -- as you say, in large multi-file diffs, I do find myself looking at a hunk and then having to scroll up or something to confirm what file it's in.

@torarnv
Copy link
Contributor

torarnv commented Oct 3, 2020

This would be great to add!

A related idea is to hyperlink the hunk context. Right now the context line number looks a bit off to me.

image

Especially for e.g. removed files:

image

I know I can disable it with line-numbers = false, but that loses out the hunk context link too.

I'm aware that the hunk context isn't at the line number reported, but as the hunk context line number doesn't refer to the first line of the context, but to the first line where there's a change, the line number is "wrongly placed" anyways, and merging it into the hunk context (function) line would simplify things visually.

dandavison added a commit that referenced this issue Oct 5, 2020
@phil-blain
Copy link
Contributor

This would also make it easier to open the file directly at the given line number for a hunk, with tools that understand the file:lineno format (like Vim with the vim-fetch extension).

@dandavison
Copy link
Owner

This is implemented in master (not yet released). To select the new behavior, you use a special style attribute file in hunk-header-style. This causes the file path to be included in the hunk header. For example: hunk-header-style = file syntax. The style for the file path is determined by file-style.

It is possible to omit the main file section and display hunk headers only. Here's an example:

[delta]
	hunk-header-style = file syntax  # use new attribute
	file-style = red omit  # set the color for the file path, but omit the main file section
	hunk-header-decoration-style = blue box ul
image

Feedback and/or testing of master branch welcome.

@dandavison
Copy link
Owner

@torarnv I don't want to lose your idea above (#309 (comment)). Maybe we should open a new ticket for it. Do you use the file/line-number hyperlinks? (Have you set things up so they open in an editor/IDE?)

@dandavison
Copy link
Owner

This is released now (v0.4.5).

@infokiller
Copy link
Author

Many thanks @dandavison, delta is great and you keep making getting better!

@Dreomite
Copy link

Is there a way to prefix every hunk with [filename: scope] or just [filename] when the diff is in the root of the file?
Using

[delta]
	hunk-header-style = file syntax
	file-style = red omit
	hunk-header-decoration-style = blue box ul

from the example shows headers only for hunks that are scoped:

image

@dandavison dandavison reopened this Dec 26, 2020
@dandavison
Copy link
Owner

@Dreomite good call, absolutely, let's get that fixed.

@dandavison
Copy link
Owner

0.5.0 was just released and contains all the changes discussed in this ticket and related PRs. Copying from the release notes:


This release introduces a cosmetic change to delta output: the line number (when full line-numbers mode is not active) is now displayed in the hunk header line, along with the hunk header code fragment, and optionally a file path. Thanks to @infokiller and @torarnv for suggesting these changes. For example, it might now look like this, if you use hunk-header-style = file line-number syntax:

image

Use hunk-header-style to configure it:

--hunk-header-style <hunk-header-style>
    Style (foreground, background, attributes) for the hunk-header. See STYLES section. Special attributes
    'file' and 'line-number' can be used to include the file path, and number of first hunk line, in the hunk
    header. If included in the hunk header, 'file' and 'line-number' are styled according to 'file-style' and
    'hunk-header-decoration-style' respectively. The style 'omit' can be used to remove the hunk header section
    from the output [default: line-number syntax]

If you are displaying the file path in the hunk header, you may want to get rid of the main file line. Use file-style = <my-file-color> omit to set the color of the file in the hunk header while deactivating the main file section.

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 a pull request may close this issue.