Skip to content

Instantly share code, notes, and snippets.

@maguroguma
Created October 16, 2022 12:38
Show Gist options
  • Save maguroguma/4ebce74f514c8a3a1711ad4a2e29d988 to your computer and use it in GitHub Desktop.
Save maguroguma/4ebce74f514c8a3a1711ad4a2e29d988 to your computer and use it in GitHub Desktop.
print the selected revision of current buffer file (require fzf.vim and fugitive.vim)
" source
function! s:list_commits() abort
let l:res = system('git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --color=always')
return split(l:res, "\n")
endfunction
" sink
function! s:select_commits(commit_hash) abort
let l:list = split(a:commit_hash, ' ')
let l:execute_command = 'Git show ' . l:list[1] . ':%'
execute l:execute_command
endfunction
command! GShow call fzf#run(fzf#wrap({
\ 'source': s:list_commits(),
\ 'sink': funcref('s:select_commits'),
\ 'options': '--ansi --prompt "git show of the buffer> "',
\ }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment