junegunn / fzf-git.sh

bash and zsh key bindings for Git objects, powered by fzf
612 stars 53 forks source link

fix: select the hash only and not those look alike in commit title #15

Closed timsu92 closed 2 years ago

timsu92 commented 2 years ago

I'm using a repo whose titles of commit are commit <hash>, and ctrl-g ctrl-h inserts two hashes.

The repo is branch release of coc.nvim

junegunn commented 2 years ago

Related: #13

Do you think we can just use awk '{print $3}'?

junegunn commented 2 years ago

Something like this:

diff --git a/fzf-git.sh b/fzf-git.sh
index 07ae22f..cfc2263 100644
--- a/fzf-git.sh
+++ b/fzf-git.sh
@@ -177,10 +177,10 @@ _fzf_git_hashes() {
     --prompt '🍡 Hashes> ' \
     --header $'CTRL-O (open in browser) ╱ CTRL-D (diff) ╱ CTRL-S (toggle sort)\n\n' \
     --bind "ctrl-o:execute-silent:bash $__fzf_git commit {}" \
-    --bind 'ctrl-d:execute:grep -o "[a-f0-9]\{7,\}" <<< {} | head -n 1 | xargs git diff > /dev/tty' \
+    --bind "ctrl-d:execute:awk '{print \$3}' <<< {} | xargs git diff > /dev/tty" \
     --color hl:underline,hl+:underline \
-    --preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | head -n 1 | xargs git show --color=always' "$@" |
-  grep -o "[a-f0-9]\{7,\}"
+    --preview "awk '{print \$3}' <<< {} | xargs git show --color=always" "$@" |
+  awk '{print $3}'
 }

 _fzf_git_remotes() {
timsu92 commented 2 years ago

I'm afraid we can't do that because branches like master of vimspector which (I guess) uses "create merge commit" will be like this: image


Sorry I met an urgent chore to do, so I left this in an odd draft😅