Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GF? with delta #1202

Closed
5 tasks done
crivotz opened this issue Dec 11, 2020 · 5 comments
Closed
5 tasks done

GF? with delta #1202

crivotz opened this issue Dec 11, 2020 · 5 comments

Comments

@crivotz
Copy link

crivotz commented Dec 11, 2020

Could there be a possibility to use delta in the GStatus? to do the diff?

I've seen some examples using fzf-preview.vim but I think it could be convenient to have it directly in fzf.vim without having to install other plugins

Here the example that I found:

let g:fzf_preview_git_status_preview_command =
    \ "[[ $(git diff --cached -- {-1}) != \"\" ]] && git diff --cached --color=always -- {-1} | delta || " .
    \ "[[ $(git diff -- {-1}) != \"\" ]] && git diff --color=always -- {-1} | delta || " .
    \ g:fzf_preview_command

Update:
Modifying line 629 I was able to get the result but it is not conservative if someone does not use delta.

  \ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--prompt', 'GitFiles?> ', '--preview', 'sh -c "(git diff --color=always -- {-1} | delta) | head -1000"']

Thanks for your help

@junegunn junegunn changed the title Gstatus? with delta GF? with delta Dec 11, 2020
@junegunn
Copy link
Owner

GStatus?

You mean :GF? (or :GFiles?), right? I fixed the title.

How about this?

diff --git a/autoload/fzf/vim.vim b/autoload/fzf/vim.vim
index cebb2fe..0eda8d6 100644
--- a/autoload/fzf/vim.vim
+++ b/autoload/fzf/vim.vim
@@ -623,10 +623,14 @@ function! fzf#vim#gitfiles(args, ...)
   " Here be dragons!
   " We're trying to access the common sink function that fzf#wrap injects to
   " the options dictionary.
+
+  let preview = executable('delta')
+        \ ? 'sh -c "git diff -- {-1} | delta"'
+        \ : 'sh -c "git diff --color=always -- {-1} | sed 1,4d; cat {-1}"'
   let wrapped = fzf#wrap({
   \ 'source':  'git -c color.status=always status --short --untracked-files=all',
   \ 'dir':     root,
-  \ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--prompt', 'GitFiles?> ', '--preview', 'sh -c "(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -1000"']
+  \ 'options': ['--ansi', '--multi', '--nth', '2..,..', '--tiebreak=index', '--prompt', 'GitFiles?> ', '--preview', preview]
   \})
   call s:remove_layout(wrapped)
   let wrapped.common_sink = remove(wrapped, 'sink*')

@crivotz
Copy link
Author

crivotz commented Dec 11, 2020

Yes I mean GFiles?, sorry for the mistake.
Great modification 👍🏻 I have to learn vimscript

@crivotz
Copy link
Author

crivotz commented Dec 11, 2020

@junegunn thanks for change but there is is a problem, I get the following messages sh: 1: [[: not found
Thanks

@junegunn
Copy link
Owner

Oh yeah, [[ may not be supported on sh depending on what it is. 65b6cdb should fix it.

@crivotz
Copy link
Author

crivotz commented Dec 12, 2020

Oh yeah, [[ may not be supported on sh depending on what it is. 65b6cdb should fix it.

Fixed, thanks 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants