Skip to content

Commit

Permalink
[Search Git Log][Search Git Status] enable integration with diff high…
Browse files Browse the repository at this point in the history
…lighters

If fzf_diff_highlighter is set, fzf.fish will pipe git diff-like output through its value. This enables integration with delta, diff-so-fancy, diff-highlighter, or https://github.com/walles/riff. Resolves #202.
  • Loading branch information
PatrickF1 committed Aug 21, 2023
1 parent 6d00ecc commit 90a66b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ set fzf_git_log_format "%H %s"

The format must be one line per commit and the hash must be the first field, or else Search Git Log will fail to determine which commits you selected.

### Integrate with a diff highlighter

To pipe the git diff previews from [Search Git Log][] and [Search Git Status][] through a highlighter tool (e.g. [delta](https://github.com/dandavison/delta) or [diff-so-fancy](https://github.com/so-fancy/diff-so-fancy)), set a command invoking the highlighter in `fzf_diff_highlighter`. It should not pipe its output to a pager:

```fish
set fzf_diff_highlighter delta --paging=never --line-numbers
# Or, if using DFS
set fzf_diff_highlighter diff-so-fancy
```

### Change the date time format used by Search History

[Search History][] shows the date time each command was executed. To change how its formatted, set your [strftime format string](https://devhints.io/strftime) in `fzf_history_time_format`. For example, this shows the date time as DD-MM-YY:
Expand Down Expand Up @@ -209,5 +219,6 @@ Find answers to these questions and more in the [project Wiki](https://github.co
[latest release badge]: https://img.shields.io/github/v/release/patrickf1/fzf.fish
[search directory]: #-search-directory
[search git log]: #-search-git-log
[search git status]: #-search-git-status
[search history]: #-search-history
[var scope]: https://fishshell.com/docs/current/#variable-scope
8 changes: 7 additions & 1 deletion functions/_fzf_search_git_log.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ function _fzf_search_git_log --description "Search the output of git log and pre
# %h gives you the abbreviated commit hash, which is useful for saving screen space, but we will have to expand it later below
set -f fzf_git_log_format '%C(bold blue)%h%C(reset) - %C(cyan)%ad%C(reset) %C(yellow)%d%C(reset) %C(normal)%s%C(reset) %C(dim normal)[%an]%C(reset)'
end

set -f preview_cmd 'git show --color=always --stat --patch {1}'
if set --query fzf_diff_highlighter
set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
end

set -f selected_log_lines (
git log --no-show-signature --color=always --format=format:$fzf_git_log_format --date=short | \
_fzf_wrapper --ansi \
--multi \
--scheme=history \
--prompt="Search Git Log> " \
--preview='git show --color=always --stat --patch {1}' \
--preview=$preview_cmd \
--query=(commandline --current-token) \
$fzf_git_log_opts
)
Expand Down
7 changes: 6 additions & 1 deletion functions/_fzf_search_git_status.fish
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ function _fzf_search_git_status --description "Search the output of git status.
if not git rev-parse --git-dir >/dev/null 2>&1
echo '_fzf_search_git_status: Not in a git repository.' >&2
else
set -f preview_cmd '_fzf_preview_changed_file {}'
if set --query fzf_diff_highlighter
set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
end

set -f selected_paths (
# Pass configuration color.status=always to force status to use colors even though output is sent to a pipe
git -c color.status=always status --short |
_fzf_wrapper --ansi \
--multi \
--prompt="Search Git Status> " \
--query=(commandline --current-token) \
--preview='_fzf_preview_changed_file {}' \
--preview=$preview_cmd \
--nth="2.." \
$fzf_git_status_opts
)
Expand Down

0 comments on commit 90a66b9

Please sign in to comment.