[git] Add diff-so-fancy as git diff

Added package diff-so-fancy and make diff use it by default for its
diffs by setting it as its diff-pager.

Added sanity function dsf which invokes diff-so-fancy if it exists or
degrades gracefully if it does not. Use this function for all git diff
needs.

Pre-fill the pager search term in git to enable jumping between changed
files with n/N.
This commit is contained in:
Marty Oehme 2020-05-28 13:35:57 +02:00
parent 17f8ca062d
commit d6a2ee7b8a
No known key found for this signature in database
GPG Key ID: 0CCB0526EFB9611A
4 changed files with 31 additions and 0 deletions

View File

@ -15,6 +15,7 @@ bison
chromium
dhcpcd
dialog
diff-so-fancy
docker
docx2txt
dunst

View File

@ -22,6 +22,8 @@
rebase = true # always rebase on pulling, obviates merge commits
[diff]
colorMoved = zebra # also color stuff that has simply been moved, in a classy zebra-color
[pager]
diff = dsf | less --tabs=4 -RFXS --pattern '(^(Date|added|deleted|modified): |^diff --git )'
[color.diff]
meta = "9"
frag = "magenta bold"

18
git/.local/bin/dsf Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env sh
# Pretty git diff display
# degrade diffs gracefully:
# prefer diff-so-fancy if it is installed,
# otherwise fallback to git's own prettifier,
# if nothing exists just pass it on
dsf() {
if exist diff-so-fancy; then
diff-so-fancy
elif exist /usr/share/git/diff-highlight/diff-highlight; then
/usr/share/git/diff-highlight/diff-highlight
else
cat
fi
}
dsf

View File

@ -9,6 +9,16 @@
## Global git settings
This is probably the first thing that needs to be customized, since it points to a different identity for each git user.
I sign all my commits by default, so take out the corresponding lines if you don't, or exchange it with your gpg key.
Git will rewrite any remotes using http(s) to use the ssh notation for pushes to github and gitlab so that, even if you set up the repository using an https url you can utilize your usual ssh key for pushing.
Finally, the configuration makes use of a custom pager called `dsf` which is also contained in this module.
It tries to use `diff-so-fancy` if that is installed on the path, otherwise uses git's internal diff prettifier.
If nothing exists it falls back to the standard output.
You can move between changed files in diffs with n/N.
Otherwise, the git config is prepared to handle lfs repositories, and it has an assortment of smaller quality of life changes, though nothing major.
## Basic git command aliases