diff --git a/README.md b/README.md index f456eb6..28fc2dc 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/functions/_fzf_search_git_log.fish b/functions/_fzf_search_git_log.fish index f5de078..ed8f4fa 100644 --- a/functions/_fzf_search_git_log.fish +++ b/functions/_fzf_search_git_log.fish @@ -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 ) diff --git a/functions/_fzf_search_git_status.fish b/functions/_fzf_search_git_status.fish index f3138a0..04e57dc 100644 --- a/functions/_fzf_search_git_status.fish +++ b/functions/_fzf_search_git_status.fish @@ -2,6 +2,11 @@ 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 | @@ -9,7 +14,7 @@ function _fzf_search_git_status --description "Search the output of git status. --multi \ --prompt="Search Git Status> " \ --query=(commandline --current-token) \ - --preview='_fzf_preview_changed_file {}' \ + --preview=$preview_cmd \ --nth="2.." \ $fzf_git_status_opts )