From 8600374371f91843064441113f4023cda1730877 Mon Sep 17 00:00:00 2001 From: Roger Gonzalez Date: Sat, 18 Mar 2023 16:40:57 -0300 Subject: General fish fixes and updates --- .config/fish/functions/_fzf_search_git_log.fish | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 .config/fish/functions/_fzf_search_git_log.fish (limited to '.config/fish/functions/_fzf_search_git_log.fish') diff --git a/.config/fish/functions/_fzf_search_git_log.fish b/.config/fish/functions/_fzf_search_git_log.fish new file mode 100644 index 00000000..3375c1d9 --- /dev/null +++ b/.config/fish/functions/_fzf_search_git_log.fish @@ -0,0 +1,28 @@ +function _fzf_search_git_log --description "Search the output of git log and preview commits. Replace the current token with the selected commit hash." + if not git rev-parse --git-dir >/dev/null 2>&1 + echo '_fzf_search_git_log: Not in a git repository.' >&2 + else + # see documentation for git format placeholders at https://git-scm.com/docs/git-log#Documentation/git-log.txt-emnem + # %h gives you the abbreviated commit hash, which is useful for saving screen space, but we will have to expand it later below + 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)' + set selected_log_lines ( + git log --color=always --format=format:$log_fmt_str --date=short | \ + _fzf_wrapper --ansi \ + --multi \ + --tiebreak=index \ + --preview='git show --color=always --stat --patch {1}' \ + --query=(commandline --current-token) \ + $fzf_git_log_opts + ) + if test $status -eq 0 + for line in $selected_log_lines + set abbreviated_commit_hash (string split --field 1 " " $line) + set full_commit_hash (git rev-parse $abbreviated_commit_hash) + set --append commit_hashes $full_commit_hash + end + commandline --current-token --replace (string join ' ' $commit_hashes) + end + end + + commandline --function repaint +end -- cgit v1.2.3