summaryrefslogtreecommitdiff
path: root/home-config/fish/functions/_fzf_search_git_log.fish
diff options
context:
space:
mode:
Diffstat (limited to 'home-config/fish/functions/_fzf_search_git_log.fish')
-rw-r--r--home-config/fish/functions/_fzf_search_git_log.fish36
1 files changed, 36 insertions, 0 deletions
diff --git a/home-config/fish/functions/_fzf_search_git_log.fish b/home-config/fish/functions/_fzf_search_git_log.fish
new file mode 100644
index 0000000..aa54724
--- /dev/null
+++ b/home-config/fish/functions/_fzf_search_git_log.fish
@@ -0,0 +1,36 @@
1function _fzf_search_git_log --description "Search the output of git log and preview commits. Replace the current token with the selected commit hash."
2 if not git rev-parse --git-dir >/dev/null 2>&1
3 echo '_fzf_search_git_log: Not in a git repository.' >&2
4 else
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 -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)'
8 end
9
10 set -f preview_cmd 'git show --color=always --stat --patch {1}'
11 if set --query fzf_diff_highlighter
12 set preview_cmd "$preview_cmd | $fzf_diff_highlighter"
13 end
14
15 set -f selected_log_lines (
16 git log --no-show-signature --color=always --format=format:$fzf_git_log_format --date=short | \
17 _fzf_wrapper --ansi \
18 --multi \
19 --scheme=history \
20 --prompt="Git Log> " \
21 --preview=$preview_cmd \
22 --query=(commandline --current-token) \
23 $fzf_git_log_opts
24 )
25 if test $status -eq 0
26 for line in $selected_log_lines
27 set -f abbreviated_commit_hash (string split --field 1 " " $line)
28 set -f full_commit_hash (git rev-parse $abbreviated_commit_hash)
29 set -f --append commit_hashes $full_commit_hash
30 end
31 commandline --current-token --replace (string join ' ' $commit_hashes)
32 end
33 end
34
35 commandline --function repaint
36end