Skip to content

Commit

Permalink
Pro tip on configuring automatic fallback (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
Encephala authored Jun 24, 2024
1 parent 39cd6a1 commit 2c1b24a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ git config --global core.pager "diff-so-fancy | less --tabs=4 -RF"
git config --global interactive.diffFilter "diff-so-fancy --patch"
```

You can look at the [pro-tips](pro-tips.md#Automatic-fallback) for a more extended configuration that transparently falls back
to default git behaviour if `diff-so-fancy` can't be found.

### Improved colors for the highlighted bits

The default Git colors are not optimal. The colors used for the screenshot above were:
Expand Down
31 changes: 31 additions & 0 deletions pro-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ zplug "so-fancy/diff-so-fancy", as:command, use:bin/git-dsf
zgenom load so-fancy/diff-so-fancy
```

## Automatic fallback

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`.
In this case, rather than getting an error message every time you run `git diff` or `git add -p`, the following configuration may help:

To make `git diff` automatically fall back to just using `less`:

```shell
git config --global core.pager "command -v diff-so-fancy >/dev/null 2>&1 && diff-so-fancy | less --tabs=4 -RF || less"
```

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:

```zsh
#!/usr/bin/zsh
command -v diff-so-fancy >/dev/null 2>&1

if [[ $? -eq 0 ]]
then
cat | diff-so-fancy --patch
else
cat
fi
```

Then, configure git (replace `dsf-filter` with whatever you named the helper script):

```shell
git config interactive.diffFilter "dsf-filter"
```

## `hg` configuration

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

0 comments on commit 2c1b24a

Please sign in to comment.