stevemao/diff-so-fancy
Save article ToRead Archive Delete · Log in Log out
1 min read · View original · github.com
diff-so-fancy
diff-so-fancy builds on the good-lookin' output of git contrib's diff-highlight to upgrade your diffs' appearances.
- Output will not be in standard patch format, but will be readable.
- No pesky
+or-at line-stars, making for easier copy-paste.
Screenshot
git diff vs git diff --color | diff-so-fancy
Usage
You can do one-off fanciness:
git diff --color | diff-so-fancyBut, you'll probably want to fancify all your diffs. Run this so git diff will use it:
git config --global core.pager "diff-so-fancy | less --tabs=1,5 -R"Or, create a git alias in your ~/.gitconfig for shorthand fanciness:
dsf = "!git diff --color $@ | diff-so-fancy"Install
For convenience, the recommended installation is via NPM:
npm install -g diff-so-fancyThis will install and link the diff-so-fancy and diff-highlight scripts.
Manual installation alternative
If you want, you can choose to install manually:
- Grab the two scripts (
diff-highlightanddiff-so-fancy) via either downloading or cloning the repo. - Place them in a location that is in your
PATH. - Set up the git
core.pagerconfig, as described above.
Note: The diff-highlight dependency is an official git-contrib script, duplicated here for convenience. If you prefer less fancy in your diff, you also use diff-highlight on it's own.
Install GNU sed
You'll need GNU sed. On Mac, it's easy to install with Homebrew.
brew install gnu-sed --with-default-names # Without the default-names flag, you'll have to use it via `gsed`Improved colors for the the highlighted bits
diff-highlight has default colors that are arguably a little nasty. They'll work fine, but you can try some fancier colors:
git config --global color.diff-highlight.oldNormal "red bold"
git config --global color.diff-highlight.oldHighlight "red bold 52"
git config --global color.diff-highlight.newNormal "green bold"
git config --global color.diff-highlight.newHighlight "green bold 22"You may also want to configure general diff colors.
Opting-out
Sometimes you will want to bypass diff-so-fancy. Easy enough:
git --no-pager diff # will avoid the global core.pager hookCredit
Originated from https://github.com/paulirish/dotfiles/blob/master/bin/diff-so-fancy
