Skip to content

Commit d243362

Browse files
committed
Don't require index line to render correctly
1 parent 11213ba commit d243362

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

diff-so-fancy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ color_code_regex=$'(\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)[m|K])?'
88
reset_color="\x1B\[m"
99
dim_magenta="\x1B\[38;05;146m"
1010

11+
git_index_line_pattern="^($color_code_regex)index .*"
12+
1113
format_diff_header () {
1214
# simplify the unified patch diff header
1315
sed -E "s/^($color_code_regex)diff --git .*$//g" | \
14-
sed -E "s/^($color_code_regex)index .*$/\
15-
\1$(print_horizontal_rule)/g" | \
16+
sed -E "/$git_index_line_pattern/{N;s/$git_index_line_pattern\n//}" | \
17+
sed -E "s/^($color_code_regex)\-\-\-(.*)$/\1$(print_horizontal_rule)\\
18+
\-\-\-\5/g" |
1619
sed -E "s/^($color_code_regex)\+\+\+(.*)$/\1\+\+\+\5\\
1720
\1$(print_horizontal_rule)/g"
1821
}

0 commit comments

Comments
 (0)