summaryrefslogtreecommitdiffstats
path: root/autoload/fzf_gitignore.vim
blob: 62e2fde2b2eba72543c5b1b633cf6d06a2565c18 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
if has_key(g:polyglot_is_disabled, 'gitignore')
  finish
endif

scriptencoding utf-8

" Copyright (c) 2017-2020 Filip Szymański. All rights reserved.
" Use of this source code is governed by an MIT license that can be
" found in the LICENSE file.

function! s:template_sink(templates) abort
  try
    let l:lines = _fzf_gitignore_create(a:templates)
  catch /^Vim(\(let\|return\)):/
    return
  endtry

  new
  setlocal filetype=gitignore

  call setline(1, l:lines)

  $-2,$delete _
  normal! gg
endfunction

function! fzf_gitignore#run() abort
  try
    let l:opts = {
          \ 'source': _fzf_gitignore_get_all_templates(),
          \ 'sink*': function('s:template_sink'),
          \ 'options': '-m --prompt="Template> " --header="gitignore.io"'
          \ }
  catch /^Vim(\(let\|return\)):/
    return
  endtry

  call fzf#run(fzf#wrap(l:opts))
endfunction

" vim: ts=2 et sw=2