Support Blame a ShowFile; better ShowFile
dblume

dblume commited on 2023-12-12 10:58:49
Showing 1 changed files, with 19 additions and 1 deletions.

... ...
@@ -193,12 +193,27 @@ function! GitBlame()
193 193
         endif
194 194
     else
195 195
         let l:fname = expand('%')
196
+        let l:hash = ''
197
+        " Show fnames will have ':' in them.
198
+        if stridx(l:fname, ':') != -1
199
+            let l:fname_parts = split(l:fname, ':')
200
+            let l:fname = l:fname_parts[-1]
201
+            let l:hash = split(l:fname_parts[0], ' ')[-1]
202
+        endif
203
+        if strlen(l:hash)
204
+            let l:bufname = 'git blame ' . l:hash . ' -- ' . l:fname
205
+            if !ShowBufInNewTab(l:bufname)
206
+                exec 'tabnew | r! git blame ' . l:hash . ' -- ' . shellescape(l:fname)
207
+                exec 'silent :file ' . fnameescape(l:bufname)
208
+            endif
209
+        else
196 210
             let l:bufname = 'git blame -- ' . l:fname
197 211
             if !ShowBufInNewTab(l:bufname)
198 212
                 exec 'tabnew | r! git blame -- ' . shellescape(l:fname)
199 213
                 exec 'silent :file ' . fnameescape(l:bufname)
200 214
             endif
201 215
         endif
216
+    endif
202 217
     0d_
203 218
     call winrestview(l:currentView)
204 219
     setl buftype=nofile
... ...
@@ -221,15 +236,18 @@ function! GitShow(commit_or_file)
221 236
                 " We lie here (' -- ') to have a filename the other git commands can use.
222 237
                 exec 'silent :file ' . fnameescape(l:bufname)
223 238
             endif
239
+            0d_
224 240
         else
241
+            let l:currentView = winsaveview()
225 242
             let l:bufname = 'git show ' . l:hash . ':' . l:fname
226 243
             if !ShowBufInNewTab(l:bufname)
227 244
                 exec 'tabnew | r! git show ' . l:hash . ':' . shellescape(l:fname)
228 245
                 exec 'silent :file ' . fnameescape(l:bufname)
229 246
             endif
247
+            0d_
248
+            call winrestview(l:currentView)
230 249
         endif
231 250
         setl buftype=nofile
232
-        0d_
233 251
     else
234 252
         echo l:hash . ' is not a git hash.'
235 253
     endif
236 254