Skip to content

Commit 2c1b24a

Browse files
authored
Pro tip on configuring automatic fallback (#493)
1 parent 39cd6a1 commit 2c1b24a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ git config --global core.pager "diff-so-fancy | less --tabs=4 -RF"
3232
git config --global interactive.diffFilter "diff-so-fancy --patch"
3333
```
3434

35+
You can look at the [pro-tips](pro-tips.md#Automatic-fallback) for a more extended configuration that transparently falls back
36+
to default git behaviour if `diff-so-fancy` can't be found.
37+
3538
### Improved colors for the highlighted bits
3639

3740
The default Git colors are not optimal. The colors used for the screenshot above were:

pro-tips.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,37 @@ zplug "so-fancy/diff-so-fancy", as:command, use:bin/git-dsf
6868
zgenom load so-fancy/diff-so-fancy
6969
```
7070

71+
## Automatic fallback
72+
73+
You might automatically distribute your git config as part of your dotfiles to new machines, where you may not have access to `diff-so-fancy`.
74+
In this case, rather than getting an error message every time you run `git diff` or `git add -p`, the following configuration may help:
75+
76+
To make `git diff` automatically fall back to just using `less`:
77+
78+
```shell
79+
git config --global core.pager "command -v diff-so-fancy >/dev/null 2>&1 && diff-so-fancy | less --tabs=4 -RF || less"
80+
```
81+
82+
Making the interactive filter automatically fall back is a bit more difficult. A helper script comes into play here, to check if `diff-so-fancy` is installed:
83+
84+
```zsh
85+
#!/usr/bin/zsh
86+
command -v diff-so-fancy >/dev/null 2>&1
87+
88+
if [[ $? -eq 0 ]]
89+
then
90+
cat | diff-so-fancy --patch
91+
else
92+
cat
93+
fi
94+
```
95+
96+
Then, configure git (replace `dsf-filter` with whatever you named the helper script):
97+
98+
```shell
99+
git config interactive.diffFilter "dsf-filter"
100+
```
101+
71102
## `hg` configuration
72103

73104
You can configure `hg diff` output to use `diff-so-fancy` by adding this alias

0 commit comments

Comments
 (0)