diff --git a/src/cli.rs b/src/cli.rs index 41483a991..22e3de2bd 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -365,7 +365,8 @@ pub struct Opt { #[structopt(long = "hunk-header-style", default_value = "syntax")] /// Style (foreground, background, attributes) for the hunk-header. See STYLES section. The - /// style 'omit' can be used to remove the hunk header section from the output. + /// special attribute 'file' can be used to include the file path in the hunk header. The style + /// 'omit' can be used to remove the hunk header section from the output. pub hunk_header_style: String, #[structopt(long = "hunk-header-decoration-style", default_value = "blue box")] diff --git a/src/config.rs b/src/config.rs index 28e571d65..6d47ac598 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,6 +32,7 @@ pub struct Config { pub file_style: Style, pub git_config_entries: HashMap, pub hunk_header_style: Style, + pub hunk_header_style_include_file_path: bool, pub hyperlinks: bool, pub hyperlinks_file_link_format: String, pub inspect_raw_lines: cli::InspectRawLines, @@ -163,6 +164,10 @@ impl From for Config { file_style, git_config_entries: opt.git_config_entries, hunk_header_style, + hunk_header_style_include_file_path: opt + .hunk_header_style + .split(' ') + .any(|s| s == "file"), hyperlinks: opt.hyperlinks, hyperlinks_file_link_format: opt.hyperlinks_file_link_format, inspect_raw_lines: opt.computed.inspect_raw_lines, diff --git a/src/delta.rs b/src/delta.rs index de9d68e25..e401e2691 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -1,4 +1,5 @@ use std::borrow::Cow; +use std::fmt::Write as FmtWrite; use std::io::BufRead; use std::io::Write; @@ -485,6 +486,13 @@ fn handle_hunk_header_line( writeln!(painter.writer)?; } if !line.is_empty() { + if config.hunk_header_style_include_file_path { + let _ = write!( + &mut painter.output_buffer, + "{}: ", + config.file_style.paint(plus_file) + ); + }; let lines = vec![(line, State::HunkHeader)]; let syntax_style_sections = Painter::get_syntax_style_sections_for_lines( &lines,