Skip to content

Commit 81f104e

Browse files
Merge branch 'next' of github.com:so-fancy/diff-so-fancy into next
2 parents 61bbdf7 + 9caa68e commit 81f104e

File tree

7 files changed

+39
-1256
lines changed

7 files changed

+39
-1256
lines changed

README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Installation is as simple as cloning this repo and then putting the `diff-so-fan
1818

1919
## Usage
2020

21+
### With git
22+
2123
Configure git to use `diff-so-fancy` for all diff output:
2224

2325
```shell
@@ -46,45 +48,53 @@ git config --global color.diff.new "green bold"
4648
git config --global color.diff.whitespace "red reverse"
4749
```
4850

51+
### With diff
52+
53+
Use `-u` with `diff` for unified output, and pipe the output to `diff-so-fancy`:
54+
55+
```shell
56+
diff -u file_a file_b | diff-so-fancy
57+
```
58+
4959
## Options
5060

5161
### markEmptyLines
5262

5363
Should the first block of an empty line be colored. (Default: true)
5464

55-
```
65+
```shell
5666
git config --bool --global diff-so-fancy.markEmptyLines false
5767
```
5868

5969
### changeHunkIndicators
6070

6171
Simplify git header chunks to a more human readable format. (Default: true)
6272

63-
```
73+
```shell
6474
git config --bool --global diff-so-fancy.changeHunkIndicators false
6575
```
6676

6777
### stripLeadingSymbols
6878

6979
Should the pesky `+` or `-` at line-start be removed. (Default: true)
7080

71-
```
81+
```shell
7282
git config --bool --global diff-so-fancy.stripLeadingSymbols false
7383
```
7484

7585
### useUnicodeRuler
7686

7787
By default, the separator for the file header uses Unicode line-drawing characters. If this is causing output errors on your terminal, set this to `false` to use ASCII characters instead. (Default: true)
7888

79-
```
89+
```shell
8090
git config --bool --global diff-so-fancy.useUnicodeRuler false
8191
```
8292

8393
### rulerWidth
8494

8595
By default, the separator for the file header spans the full width of the terminal. Use this setting to set the width of the file header manually.
8696

87-
```
97+
```shell
8898
git config --global diff-so-fancy.rulerWidth 47 # git log's commit header width
8999
```
90100

@@ -109,6 +119,10 @@ Pull requests are quite welcome, and should target the [`next` branch](https://g
109119
* [Hacking and Testing](hacking-and-testing.md)
110120
* [History](history.md)
111121

122+
## Alternatives
123+
124+
* https://github.com/dandavison/delta
125+
112126
## License
113127

114128
MIT

diff-so-fancy

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env perl
22

3-
my $VERSION = "1.4.0";
3+
my $VERSION = "1.4.1";
44

55
#################################################################################
66

@@ -345,10 +345,10 @@ sub do_dsf_stuff {
345345
}
346346

347347
my $next = shift(@$input);
348-
my ($file1) = $next =~ /rename from (.+)/;
348+
my ($file1) = $next =~ /rename from (.+?)(\e|\t|$)/;
349349

350350
$next = shift(@$input);
351-
my ($file2) = $next =~ /rename to (.+)/;
351+
my ($file2) = $next =~ /rename to (.+?)(\e|\t|$)/;
352352

353353
if ($file1 && $file2) {
354354
# We may not have extracted this yet, so we pull from the config if not
@@ -526,7 +526,7 @@ sub should_print_unicode {
526526

527527
# Otherwise, assume we're piping to less(1)
528528
my ($less_env_var, $less_charset) = get_less_charset();
529-
if ($less_charset =~ /utf-?8/i) {
529+
if ($less_charset && $less_charset =~ /utf-?8/i) {
530530
return 1;
531531
}
532532

@@ -663,14 +663,10 @@ sub file_change_string {
663663
# If the files aren't the same it's a rename
664664
} elsif ($file_1 ne $file_2) {
665665
my ($old, $new) = DiffHighlight::highlight_pair($file_1,$file_2,{only_diff => 1});
666+
# highlight_pair already includes reset_color, but adds newline characters that need to be trimmed off
666667
$old = trim($old);
667668
$new = trim($new);
668-
669-
# highlight_pair resets the colors, but we want it to be the meta color
670-
$old =~ s/(\e0?\[m)/$1$meta_color/g;
671-
$new =~ s/(\e0?\[m)/$1$meta_color/g;
672-
673-
return "renamed: $old to $new";
669+
return "renamed: $old$meta_color to $new"
674670
# Something we haven't thought of yet
675671
} else {
676672
return "$file_1 -> $file_2";

hacking-and-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ You can lint your scripts via shellcheck, our CI bots will also check.
3333

3434
```sh
3535
brew install shellcheck
36-
shellcheck diff-so-fancy update-deps.sh
36+
shellcheck *.sh

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff-so-fancy",
3-
"version": "1.2.5",
3+
"version": "1.3.0",
44
"description": "Good-lookin' diffs with diff-highlight and more",
55
"bin": {
66
"diff-so-fancy": "diff-so-fancy"

pro-tips.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
#### One-off fanciness or a specific diff-so-fancy alias
44

5-
You can do also do a one-off or a specific `diff-so-fancy` alias:
5+
You can do also do a one-off:
66
```shell
77
git diff --color | diff-so-fancy
8-
9-
git config --global alias.dsf '!f() { [ -z "$GIT_PREFIX" ] || cd "$GIT_PREFIX" '\
10-
'&& git diff --color "$@" | diff-so-fancy | less --tabs=4 -RFX; }; f'
8+
```
9+
or configure an alias and a corresponding pager to use `diff-so-fancy`:
10+
```shell
11+
git config --global alias.dsf "diff --color"
12+
git config --global pager.dsf "diff-so-fancy | less --tabs=4 -RFXS"
1113
```
1214

1315
#### Opting-out
@@ -34,19 +36,19 @@ You can pre-seed your `less` pager with a search pattern, so you can move
3436
between files with `n`/`N` keys:
3537
```ini
3638
[pager]
37-
diff = diff-so-fancy | less --tabs=4 -RFX --pattern '^(Date|added|deleted|modified): '
39+
diff = diff-so-fancy | less --tabs=4 -RFXS --pattern '^(Date|added|deleted|modified): '
3840
```
3941

4042
#### Zsh plugin providing diff-so-fancy
4143

4244
Zsh plugin [zdharma/zsh-diff-so-fancy](https://github.com/zdharma/zsh-diff-so-fancy) has this
4345
project as a submodule so installing the plugin installs `diff-so-fancy`. The plugin provides
44-
subcommand `git dsf` out of the box. Installation with Zplugin, Zplug and Zgen:
46+
subcommand `git dsf` out of the box. Installation with Zinit, Zplug and Zgen:
4547

4648
```zsh
47-
# Zplugin
48-
zplugin ice as"program" pick"bin/git-dsf"
49-
zplugin light zdharma/zsh-diff-so-fancy
49+
# zinit
50+
zinit ice lucid as"program" pick"bin/git-dsf"
51+
zinit load zdharma/zsh-diff-so-fancy
5052

5153
# Or zplug
5254
zplug "zdharma/zsh-diff-so-fancy", as:command, use:bin/git-dsf

0 commit comments

Comments
 (0)