From d2028455886da8df0413591ab167c6b7da281e06 Mon Sep 17 00:00:00 2001 From: Thomas Jachmann Date: Mon, 25 Apr 2022 18:25:18 +0200 Subject: [PATCH 1/2] Allow combination of bang and parameters Before, it was either possible to use the bang command or specify further parameters. Now, you can combine them, eg for: :Tig! blame This will open the blame view for a file by executing: tig blame -- Also, the double dash was added in front of the current file name for better distinction between parameters and paths. --- README.md | 5 +++++ plugin/tig.vim | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d764157..ff43c5a 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,11 @@ Show commit log of current file: :Tig! ``` +Show blame view of current file: +``` +:Tig! blame +``` + Configuration ------------- Tig executable: `let g:tig_executable = 'tig'` diff --git a/plugin/tig.vim b/plugin/tig.vim index 360fcec..553121a 100644 --- a/plugin/tig.vim +++ b/plugin/tig.vim @@ -31,14 +31,19 @@ if has('nvim') call termopen(g:tig_executable . ' ' . a:arg, s:callback) endfunction - exec g:tig_open_command + let arg = '' + if a:0 > 0 + let arg .= ' ' . a:1 + endif if a:bang > 0 - call s:tigopen(current) - elseif a:0 > 0 - call s:tigopen(a:1) - else - call s:tigopen(g:tig_default_command) + let arg .= ' -- ' . current + endif + if len(arg) == 0 + let arg = g:tig_default_command endif + + exec g:tig_open_command + call s:tigopen(arg) setlocal nonumber setlocal norelativenumber setlocal signcolumn=no From 66aa362ced364ad5ae36cbb969de92f2ab30551e Mon Sep 17 00:00:00 2001 From: Thomas Jachmann Date: Tue, 26 Apr 2022 09:22:00 +0200 Subject: [PATCH 2/2] Allow variable expansion for % and + --- README.md | 12 ++++++++++++ plugin/tig.vim | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff43c5a..52e39bd 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,18 @@ Show blame view of current file: :Tig! blame ``` +You can also manually craft tig commands by using variable expansion: + +* `%` will expand to the current file path +* `+` will expand to the current line number (prefixed with `+` so that tig + will jump to that line) + +``` +:Tig! blame + +:Tig blame + -- % +``` +(These two actually result in the same tig command line being executed.) + Configuration ------------- Tig executable: `let g:tig_executable = 'tig'` diff --git a/plugin/tig.vim b/plugin/tig.vim index 553121a..ab8a34e 100644 --- a/plugin/tig.vim +++ b/plugin/tig.vim @@ -33,7 +33,10 @@ if has('nvim') let arg = '' if a:0 > 0 - let arg .= ' ' . a:1 + let args = a:1 + let args = substitute(args, '%', current, '') + let args = substitute(args, '+', '+' . line('.'), '') + let arg .= ' ' . args endif if a:bang > 0 let arg .= ' -- ' . current