Last active
July 26, 2020 14:59
-
-
Save garfvl/e9b914a3c6000f4aff56894f43ee9c72 to your computer and use it in GitHub Desktop.
Display commit information during interactive rebase in (neo)VIM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Display `git show <commit>` during interactive rebase in the preview window | |
function! PreviewCommitDuringRebase() | |
try | |
if getline(".") =~ '^\s*#' | |
throw "This is a comment line, do not preview" | |
endif | |
" get 2nd column == commit hash. Will fail if 2nd does not exists | |
let hash = split(getline('.'))[1] | |
let commitshow = systemlist("git show " . hash) | |
if v:shell_error != 0 | |
throw "git show returned an error" | |
endif | |
" Launch preview edition | |
silent execute "noautocmd pedit Commit " . hash | |
silent wincmd P " jump to preview window | |
if &previewwindow | |
setlocal buftype=nofile " buffer should not be written | |
setlocal syntax=git " colors == git | |
wincmd L " put window to the right | |
call setline(1, commitshow) " push command output to the buffer | |
wincmd p " back to old window | |
endif | |
catch | |
" something gone wrong -> close preview | |
silent! exe ":pclose!" | |
endtry | |
endfunction | |
" Inside the `git-rebase-todo` file, try to launch the preview on cursor | |
" movement | |
:autocmd CursorMoved,CursorMovedI */.git/rebase-merge/git-rebase-todo :call PreviewCommitDuringRebase() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can be combined wit tig rebase bindings:
.tigrc
: