Make vim (git) Log accept arguments
dblume

dblume commited on 2023-12-15 22:12:49
Showing 1 changed files, with 11 additions and 5 deletions.

... ...
@@ -339,23 +339,29 @@ function! GitDiff()
339 339
 endfunction
340 340
 command Diff :call GitDiff()
341 341
 
342
-function! GitLog(flags)
342
+function! GitLog(...)
343 343
     let l:fname = expand('%')
344 344
     if stridx(l:fname, ' -- ') != -1
345 345
         let l:fname = split(l:fname, ' -- ')[-1]
346 346
     elseif stridx(l:fname, ':') != -1
347 347
         let l:fname = split(l:fname, ':')[-1]
348 348
     endif
349
-    let l:bufname = 'git log ' . a:flags . '-- ' . l:fname
349
+    let l:args = a:1
350
+    if strlen(l:args)
351
+        " Add a space to the end
352
+	let l:args = l:args . " "
353
+    endif
354
+    let l:bufname = 'git log ' . l:args . '-- ' . l:fname
350 355
     if !ShowBufInNewTab(l:bufname)
351
-        exec 'tabnew | r! git log --no-color --graph --date=short ' . a:flags . '--pretty="format:\%h \%ad \%s \%an \%d" -- ' . shellescape(l:fname)
356
+        exec 'tabnew | r! git log --no-color --graph --date=short ' . l:args . '--pretty="format:\%h \%ad \%s \%an \%d" -- ' . shellescape(l:fname)
352 357
         setl buftype=nofile
353 358
         0d_
354 359
         exec 'silent :file ' . fnameescape(l:bufname)
355 360
     endif
356 361
 endfunction
357
-command Logall :call GitLog('--all ')
358
-command Log :call GitLog('')
362
+
363
+" Handy arguments are --all, --merges, --date-order, --first-parent, --ancestry-path
364
+command -nargs=* Log :call GitLog(<q-args>)
359 365
 
360 366
 " pastetoggle
361 367
 nmap <leader>p :set invpaste paste?<cr>
362 368