File: glob_linux.vim

package info (click to toggle)
vim-addon-mw-utils 0.2-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 132 kB
  • sloc: makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,517 bytes parent folder | download | duplicates (3)
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
42

" TODO refactor: create glob function
" noremap \og :call<space>glob_linux#FileByGlobCurrentDir('**/*'.input('glob open '),"\\.git\\<bar>\\.hg\\<bar>node_modules\\<bar>\\.pyc" )<cr>
" noremap \og :call<space>glob_linux#FileByGlobCurrentDir('**/*'.input('glob open '),"default" )<cr>
function! glob_linux#FileByGlobCurrentDir(glob, exclude_pattern)
  if a:exclude_pattern == "default"
    let exclude_pattern = '\.git\|\.hg\|node_modules\|\.pyc'
  else
    let exclude_pattern = a:exclude_pattern
  endif

  " let files = split(glob(a:glob),"\n")
  let g = a:glob
  let replace = {'**': '.*','*': '[^/\]*','.': '\.'}
  let g = substitute(g, '\(\*\*\|\*\|\.\)', '\='.string(replace).'[submatch(1)]','g')

  let exclude = exclude_pattern == '' ? '' : ' | grep -v -e '.shellescape(exclude_pattern)

  let cmd = 'find | grep -e '.shellescape(g).exclude
  let files = split(system(cmd),"\n")
  " for nom in a:excludes
  "   call filter(files,nom)
  " endfor
  if len(files) > 1000
    echoe "more than ".2000." files - would be too slow. Open the file in another way"
  else
    if empty(files)
      echoe "no file found"
    elseif len(files) == 1
      exec 'e '.fnameescape(files[0])
    else
      let g:abc=7
      call tovl#ui#filter_list#ListView({
            \ 'number' : 1,
            \ 'selectByIdOrFilter' : 1,
            \ 'Continuation' : funcref#Function('exec "e ".fnameescape(ARGS[0])'),
            \ 'items' : files,
            \ 'cmds' : ['wincmd J']
            \ })
    endif
  endif
endfunction