An open API service indexing awesome lists of open source software.

https://github.com/z-shell/zsh-diff-so-fancy

⚙️ The diff-so-fancy for Zsh
https://github.com/z-shell/zsh-diff-so-fancy

awesome-zsh-plugins diff diff-utils git-diff git-difftool zsh zsh-plugin

Last synced: about 1 month ago
JSON representation

⚙️ The diff-so-fancy for Zsh

Awesome Lists containing this project

README

          



Logo

❮ Zi ❯ Plugin - zsh-diff-so-fancy



zsh-diff-so-fancy



# zsh-diff-so-fancy

A simple plugin integrating [so-fancy/diff-so-fancy](https://github.com/so-fancy/diff-so-fancy) into Zsh. It provides:

- `git dsf`: A subcommand to run Git diffs through diff-so-fancy
- `fancy-diff`: A helper to run a unified diff and beautify it with diff-so-fancy

## Quick Start

1. **Install** [diff-so-fancy](https://github.com/so-fancy/diff-so-fancy#installation) or load it via your preferred method.
2. **Load the plugin** in your `.zshrc` or plugin manager:
```shell
# Example using Zi
zi ice as'program' pick'bin/*'
zi light z-shell/zsh-diff-so-fancy
```
3. **Use** the commands:
- `git dsf ` to see a diff rendered by diff-so-fancy
- `fancy-diff ` to compare two files with diff-so-fancy

## Customization

You can customize the `less` options by setting these environment variables in your `.zshrc` before loading the plugin:

```shell
# 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.

## Manual Configuration

```shell
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`
```

### Git Integration

```shell
# 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"
```

### diff-so-fancy Options

- **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.

### Plugin Details

- Both `fancy-diff` and `git-dsf` use the `--patch` flag with `diff-so-fancy` to 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](https://wiki.zshell.dev/community/zsh_plugin_standard) and provides an unload function for plugin managers that support unloading.
- The plugin checks if `diff-so-fancy` is installed and provides a helpful warning if it's not found.

### Installation with [Zi](https://github.com/z-shell/zi)

```shell
zi ice as'null' sbin'bin/*'
zi light z-shell/zsh-diff-so-fancy
```

Or:

```shell
zi ice as'program' pick'bin/*'
zi light z-shell/zsh-diff-so-fancy
```

This places `diff-so-fancy`, `fancy-diff`, and `git-dsf` in `$PATH`, adding the `dsf` subcommand to Git automatically.

## Other Plugin Managers

- **Zplug**
```shell
zplug "z-shell/zsh-diff-so-fancy", as:command, use:"bin/"
```
- **Zgen**
```shell
zgen load z-shell/zsh-diff-so-fancy
```