wvanlint / twf

Standalone tree view file explorer, inspired by fzf.
271 stars 11 forks source link

Panic when previewing nvim #2

Closed hashtegner closed 4 years ago

hashtegner commented 4 years ago

Hello, I ran with NeoVim it raises a panic.

:!twf
panic: device not configured

goroutine 1 [running]:
main.main()
        /Users/alesshh/.asdf/installs/golang/1.14.2/packages/pkg/mod/github.com/wvanlint/twf@v0.0.0-20200526060914-43686a43dde1/cmd/twf/main.go:67 +0x935

shell returned 2

This issue didn't occur when I ran the inside vim 8. Any tips to fix or contribute?

wvanlint commented 4 years ago

Thanks for reporting! I just added an additional section for nvim configuration, let me know if the following works for you.

function! TwfExit(path)
  function! TwfExitClosure(job_id, data, event) closure
    bd!
    try
      let out = filereadable(a:path) ? readfile(a:path) : []
    finally
      silent! call delete(a:path)
    endtry
    if !empty(out)
      execute 'edit! ' . out[0]
    endif
  endfunction
  return funcref('TwfExitClosure')
endfunction

function! Twf()
  let temp = tempname()
  call termopen('twf ' . @% . ' > ' . temp, { 'on_exit': TwfExit(temp) })
  startinsert
endfunction

nnoremap <silent> <Space>t :call Twf()<CR>
hashtegner commented 4 years ago

Wow, it works. Thanks!