Skip to content

Commit 039a86d

Browse files
committed
[Search Git Log] add option for customizing commit log format
1 parent 7b14fa7 commit 039a86d

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,13 @@ Find more ideas and implementation tips in the [Cookbook](https://github.com/Pat
145145

146146
[Search Directory][], by default, calls `ls` to preview directories and `bat` to preview [regular files](https://stackoverflow.com/questions/6858452).
147147

148-
To change the directory preview command (e.g. to use one of the many `ls` replacements such as `exa`), set `fzf_preview_dir_cmd` to the desired command:
148+
To use your own directory preview command (e.g. to use one of the many `ls` replacements such as `exa`), set it in `fzf_preview_dir_cmd`:
149149

150150
```fish
151151
set fzf_preview_dir_cmd exa --all --color=always
152152
```
153153

154-
And to change the file preview command (e.g. to `cat` to avoid having to install `bat`, or to add logic for previewing images), set `fzf_preview_file_cmd` to the desired command:
154+
And to use your own file preview command (e.g. to `cat` to avoid having to install `bat`, or to add logic for previewing images), set it in `fzf_preview_file_cmd`:
155155

156156
```fish
157157
set fzf_preview_file_cmd cat -n
@@ -161,14 +161,24 @@ Omit the target path for both variables as `fzf.fish` will itself [specify the a
161161

162162
### Change what files are listed in Search Directory
163163

164-
To pass custom options to `fd` when it is executed to populate the list of files for [Search Directory][], set them in `fzf_fd_opts`. For example, to include hidden files but not `.git`:
164+
To pass custom options to `fd` when it is executed to populate the list of files for [Search Directory][], set them in `fzf_fd_opts`. For example, this includes hidden files but not `.git`:
165165

166166
```fish
167167
set fzf_fd_opts --hidden --exclude=.git
168168
```
169169

170170
<a id='fd-gi'></a>By default, `fd` hides files listed in `.gitignore`. You can disable this behavior by adding the `--no-ignore` flag to `fzf_fd_opts`.
171171

172+
### Change the commit formatting used by Search Git Log
173+
174+
[Search Git Log][] calls `git log --format` to format the list of commits. To use your own [commit log format](https://git-scm.com/docs/git-log#Documentation/git-log.txt-emnem), set it in `fzf_git_log_format`. For example, this shows the hash and subject for each commit:
175+
176+
```fish
177+
set fzf_git_log_format "%H %s"
178+
```
179+
180+
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.
181+
172182
## Further reading
173183

174184
Find answers to these questions and more in the [project Wiki](https://github.com/PatrickF1/fzf.fish/wiki):
@@ -188,4 +198,5 @@ Find answers to these questions and more in the [project Wiki](https://github.co
188198
[fzf]: https://github.com/junegunn/fzf
189199
[latest release badge]: https://img.shields.io/github/v/release/patrickf1/fzf.fish
190200
[search directory]: #-search-directory
201+
[search git log]: #-search-git-log
191202
[var scope]: https://fishshell.com/docs/current/#variable-scope

functions/_fzf_search_git_log.fish

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ function _fzf_search_git_log --description "Search the output of git log and pre
22
if not git rev-parse --git-dir >/dev/null 2>&1
33
echo '_fzf_search_git_log: Not in a git repository.' >&2
44
else
5-
# see documentation for git format placeholders at https://git-scm.com/docs/git-log#Documentation/git-log.txt-emnem
6-
# %h gives you the abbreviated commit hash, which is useful for saving screen space, but we will have to expand it later below
7-
set log_fmt_str '%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)'
5+
if not set --query fzf_git_log_format
6+
# %h gives you the abbreviated commit hash, which is useful for saving screen space, but we will have to expand it later below
7+
set 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)'
8+
end
89
set selected_log_lines (
9-
git log --no-show-signature --color=always --format=format:$log_fmt_str --date=short | \
10+
git log --no-show-signature --color=always --format=format:$fzf_git_log_format --date=short | \
1011
_fzf_wrapper --ansi \
1112
--multi \
1213
--tiebreak=index \

0 commit comments

Comments
 (0)