diff options
| author | Ryan Schanzenbacher <ryan@rschanz.org> | 2024-04-05 11:57:45 -0400 |
|---|---|---|
| committer | Ryan Schanzenbacher <ryan@rschanz.org> | 2024-04-05 11:57:45 -0400 |
| commit | b88d77fb2d0d5028a6f5670695dee6bec129501f (patch) | |
| tree | 2536b0461d297e647cf07157641c9b1223339adf /home-config/fish/functions/_fzf_search_git_log.fish | |
| parent | 776a7ca55d2d2c3f396de91db1c6c3c5065012cd (diff) | |
ahhh sloppy fish, still needs fixing, esp with the vars
Diffstat (limited to 'home-config/fish/functions/_fzf_search_git_log.fish')
| -rw-r--r-- | home-config/fish/functions/_fzf_search_git_log.fish | 36 |
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 @@ | |||
| 1 | function _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 | ||
| 36 | end | ||
