A simple plugin integrating so-fancy/diff-so-fancy into Zsh. It provides:
git dsf: A subcommand to run Git diffs through diff-so-fancyfancy-diff: A helper to run a unified diff and beautify it with diff-so-fancy
- Install diff-so-fancy or load it via your preferred method.
- Load the plugin in your
.zshrcor plugin manager:# Example using Zi zi ice as'program' pick'bin/*' zi light z-shell/zsh-diff-so-fancy
- Use the commands:
git dsf <files>to see a diff rendered by diff-so-fancyfancy-diff <file1> <file2>to compare two files with diff-so-fancy
You can customize the less options by setting these environment variables in your .zshrc before loading the plugin:
# Customize less options for fancy-diff
export FANCY_DIFF_LESS_OPTS="--tabs=2 -RFX"
# Customize less options for git dsf
export GIT_DSF_LESS_OPTS="--tabs=2 -FRXS"The default is --tabs=4 -FRXSi for both commands if not specified.
diff-so-fancy --colors # Show recommended color config
diff-so-fancy --set-defaults # Configure Git to use diff-so-fancy with suggested colors
diff-so-fancy --patch # Patch mode, interoperable with `git add --patch`# Use diff-so-fancy for all diffs
git config --global core.pager "diff-so-fancy | less --tabs=4 -RFX"
# Use diff-so-fancy for `git add --patch`
git config --global interactive.diffFilter "diff-so-fancy --patch"- markEmptyLines (bool, default: true) Color the first block of an empty line.
- changeHunkIndicators (bool, default: true) Simplify Git header chunks to a more readable format.
- stripLeadingSymbols (bool, default: true)
Remove leading
+or-from lines. - useUnicodeRuler (bool, default: true) Use Unicode line-drawing characters for file headers (disable if your terminal cannot display them).
- rulerWidth (int, default: full width) Set a fixed width for the file header separator.
- Both
fancy-diffandgit-dsfuse the--patchflag withdiff-so-fancyto preserve the original diff format in the output, which is useful for interoperability with tools that parse diff output. - The plugin follows the Zsh Plugin Standard and provides an unload function for plugin managers that support unloading.
- The plugin checks if
diff-so-fancyis installed and provides a helpful warning if it's not found.
Installation with Zi
zi ice as'null' sbin'bin/*'
zi light z-shell/zsh-diff-so-fancyOr:
zi ice as'program' pick'bin/*'
zi light z-shell/zsh-diff-so-fancyThis places diff-so-fancy, fancy-diff, and git-dsf in $PATH, adding the dsf subcommand to Git automatically.
- Zplug
zplug "z-shell/zsh-diff-so-fancy", as:command, use:"bin/"
- Zgen
zgen load z-shell/zsh-diff-so-fancy
