Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function! s:flatten(xss) abort
let memo = []
for xs in a:xss
for x in xs
call add(memo, x)
endfor
endfor
return memo
endfunction
function! s:f(cwd, file, keyword) abort
let path = a:cwd . '/' . a:file
if isdirectory(path)
return s:grep(path, a:keyword)
else
for line in readfile(path)
if line =~ a:keyword
return [path]
endif
endfor
return []
endif
endfunction
function! s:grep(cwd, keyword) abort
let stdout = system(printf("ls %s", a:cwd))
if stdout =~ 'No such file'
return []
endif
let files = split(stdout, "\n")
return s:flatten(map(files, { _, file -> s:f(a:cwd, file, a:keyword) }))
endfunction
echo s:grep(getcwd(), 'aaa')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.