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

Detect gsed and use it if it exists #25

Merged
merged 2 commits into from
Feb 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions diff-so-fancy
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@

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

hash gsed 2>/dev/null && SED=gsed || SED=sed

color_code_regex=$'(\x1B\\[([0-9]{1,2}(;[0-9]{1,2})?)[m|K])?'
reset_color="\x1B\[m"
dim_magenta="\x1B\[38;05;146m"

format_diff_header () {
# simplify the unified patch diff header
sed -E "s/^($color_code_regex)diff --git .*$//g" | \
sed -E "s/^($color_code_regex)index .*$/\
$SED -E "s/^($color_code_regex)diff --git .*$//g" | \
$SED -E "s/^($color_code_regex)index .*$/\
\1$(print_horizontal_rule)/g" | \
sed -E "s/^($color_code_regex)\+\+\+(.*)$/\1\+\+\+\5\\
$SED -E "s/^($color_code_regex)\+\+\+(.*)$/\1\+\+\+\5\\
\1$(print_horizontal_rule)/g"
}

colorize_context_line () {
# extra color for @@ context line
sed -E "s/@@$reset_color $reset_color(.*$)/@@ $dim_magenta\1/g"
$SED -E "s/@@$reset_color $reset_color(.*$)/@@ $dim_magenta\1/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'
printf "%$(tput cols)s\n"| $SED 's/ /─/g'
}

# run it.
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Note: The `diff-highlight` dependency is an [official git-contrib script](https:
### Install GNU `sed`
You'll need GNU sed. On Mac, it's easy to install with Homebrew.
```shell
brew install gnu-sed --with-default-names # Without the default-names flag, you'll have to use it via `gsed`
brew install gnu-sed
```

### Improved colors for the the highlighted bits
Expand Down