Skip to content

Commit

Permalink
mark empty newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Feb 11, 2016
1 parent b1c4c93 commit 5c3aa39
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions diff-so-fancy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ fi
color_code_regex=$'(\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)[m|K])?'
reset_color="\x1B\[m"
dim_magenta="\x1B\[38;05;146m"
invert_color="\x1B\[7m"

format_diff_header () {
# simplify the unified patch diff header
Expand All @@ -28,14 +29,18 @@ colorize_context_line () {
$SED -E "s/@@$reset_color $reset_color(.*$)/@@ $dim_magenta\1/g"
}

mark_empty_lines () {
$SED -E "s/^$color_code_regex[\+\-]$reset_color\s*$/$invert_color\1 $reset_color/g"
}

strip_leading_symbols () {
# strip the + and -
$SED -E "s/^($color_code_regex)[\+\-]/\1 /g"
$SED -E "s/^$color_code_regex[\+\-]/\1 /g"
}

print_horizontal_rule () {
printf "%$(tput cols)s\n"| $SED 's/ /─/g'
}

# run it.
cat $input | $diff_highlight | format_diff_header | colorize_context_line | strip_leading_symbols
cat $input | $diff_highlight | format_diff_header | colorize_context_line | mark_empty_lines | strip_leading_symbols

0 comments on commit 5c3aa39

Please sign in to comment.