From a1cb01da5b2c84ebfbe86a02bfb2e7ef9d830d50 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Thu, 18 Mar 2021 00:57:30 -0400 Subject: [PATCH] Provide :Gedit - to open previous :Git output Also, provide :GBrowse - to open the first URL contained in that output. --- autoload/fugitive.vim | 39 +++++++++++++++++++++++++++++++++++---- doc/fugitive.txt | 1 + 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim index 0142115..dc137b6 100644 --- a/autoload/fugitive.vim +++ b/autoload/fugitive.vim @@ -2321,6 +2321,20 @@ function! s:TempState(...) abort return get(s:temp_files, s:cpath(fnamemodify(a:0 ? a:1 : @%, ':p')), {}) endfunction +function! fugitive#Result(...) abort + if !a:0 || a:1 =~# '^-\=$' + return get(g:, '_fugitive_last_job', {}) + elseif type(a:1) == type(0) + return s:TempState(bufname(a:1)) + elseif type(a:1) == type('') + return s:TempState(a:1) + elseif type(a:1) == type({}) && has_key(a:1, 'file') + return s:TempState(a:1.file) + else + return {} + endif +endfunction + function! s:TempReadPre(file) abort if has_key(s:temp_files, s:cpath(a:file)) let dict = s:temp_files[s:cpath(a:file)] @@ -4741,6 +4755,14 @@ function! s:OpenParse(string, wants_cmd) abort endwhile if len(args) let file = join(args) + if file ==# '-' + let result = fugitive#Result() + if has_key(result, 'file') + let file = s:fnameescape(result.file) + else + throw 'fugitive: no previous command output' + endif + endif elseif empty(expand('%')) let file = '' elseif empty(s:DirCommitFile(@%)[1]) && s:Relative('./') !~# '^\./\.git\>' @@ -5932,10 +5954,19 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo endif let validremote = '\.\|\.\=/.*\|[[:alnum:]_-]\+\%(://.\{-\}\)\=' if arg ==# '-' - if a:count >= 0 - return 'echoerr ' . string('fugitive: ''-'' no longer required to get persistent URL if range given') - else - return 'echoerr ' . string('fugitive: use :0GBrowse instead of :GBrowse -') + let remote = '' + let rev = '' + let result = fugitive#Result() + if filereadable(get(result, 'file', '')) + for line in readfile(result.file, 4096) + let rev = s:fnameescape(matchstr(line, '\]*[^[:space:]<>.,;:"''!?]')) + if len(rev) + break + endif + endfor + if empty(rev) + return 'echoerr ' . string('fugitive: no URL found in output of last :Git') + endif endif elseif !exists('l:remote') let remote = matchstr(arg, '@\zs\%('.validremote.'\)$') diff --git a/doc/fugitive.txt b/doc/fugitive.txt index 987cdce..ac20d21 100644 --- a/doc/fugitive.txt +++ b/doc/fugitive.txt @@ -590,6 +590,7 @@ Makefile The file named Makefile in the work tree !3^2 The second parent of the commit owning buffer #3 .git/config The repo config file : The |fugitive-summary| buffer. +- A temp file containing the last |:Git| invocation's output STATUSLINE *fugitive-statusline*