Skip to content

Commit e0fa502

Browse files
committed
Detect gsed and use it if it exists
1 parent 11213ba commit e0fa502

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

diff-so-fancy

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,33 @@
44

55
diff_highlight="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/third_party/diff-highlight/diff-highlight"
66

7+
hash gsed 2>/dev/null && SED=gsed || SED=sed
8+
79
color_code_regex=$'(\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)[m|K])?'
810
reset_color="\x1B\[m"
911
dim_magenta="\x1B\[38;05;146m"
1012

1113
format_diff_header () {
1214
# simplify the unified patch diff header
13-
sed -E "s/^($color_code_regex)diff --git .*$//g" | \
14-
sed -E "s/^($color_code_regex)index .*$/\
15+
$SED -E "s/^($color_code_regex)diff --git .*$//g" | \
16+
$SED -E "s/^($color_code_regex)index .*$/\
1517
\1$(print_horizontal_rule)/g" | \
16-
sed -E "s/^($color_code_regex)\+\+\+(.*)$/\1\+\+\+\5\\
18+
$SED -E "s/^($color_code_regex)\+\+\+(.*)$/\1\+\+\+\5\\
1719
\1$(print_horizontal_rule)/g"
1820
}
1921

2022
colorize_context_line () {
2123
# extra color for @@ context line
22-
sed -E "s/@@$reset_color $reset_color(.*$)/@@ $dim_magenta\1/g"
24+
$SED -E "s/@@$reset_color $reset_color(.*$)/@@ $dim_magenta\1/g"
2325
}
2426

2527
strip_leading_symbols () {
2628
# strip the + and -
27-
sed -E "s/^($color_code_regex)[\+\-]/\1 /g"
29+
$SED -E "s/^($color_code_regex)[\+\-]/\1 /g"
2830
}
2931

3032
print_horizontal_rule () {
31-
printf "%$(tput cols)s\n"| sed 's/ /─/g'
33+
printf "%$(tput cols)s\n"| $SED 's/ /─/g'
3234
}
3335

3436
# run it.

0 commit comments

Comments
 (0)