Skip to content

Commit

Permalink
feat: add yazi support
Browse files Browse the repository at this point in the history
  • Loading branch information
vargasd authored and voldikss committed Oct 5, 2023
1 parent eeb3f6b commit 6e81602
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,16 @@ command! Vifm FloatermNew vifm
<img src="https://user-images.githubusercontent.com/43941510/77137476-3c888100-6ac2-11ea-90f2-2345c881aa8f.gif"/>
</details>

#### [yazi](https://github.com/sxyazi/yazi)

There is also a [yazi wrapper](./autoload/floaterm/wrapper/yazi.vim)

Try `:FloatermNew yazi` or define a new command:

```vim
command! Yazi FloatermNew yazi
```

#### [lazygit](https://github.com/jesseduffield/lazygit)

Furthermore, you can also use other command-line programs, such as lazygit, htop, ncdu, etc.
Expand Down
43 changes: 43 additions & 0 deletions autoload/floaterm/wrapper/yazi.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
" vim:sw=2:
" ============================================================================
" FileName: yazi.vim
" Author: Sam Varga <sam@vargasd.com>
" GitHub: https://github.com/vargasd
" ============================================================================

function! floaterm#wrapper#yazi#(cmd, jobopts, config) abort
let s:yazi_tmpfile = tempname()
let original_dir = getcwd()
lcd %:p:h

let cmdlist = split(a:cmd)
let cmd = 'yazi --chooser-file "' . s:yazi_tmpfile . '"'
if len(cmdlist) > 1
let cmd .= ' ' . join(cmdlist[1:], ' ')
else
let cmd .= ' "' . getcwd() . '"'
endif

exe "lcd " . original_dir
let cmd = [&shell, &shellcmdflag, cmd]
let jobopts = {'on_exit': funcref('s:yazi_callback')}
call floaterm#util#deep_extend(a:jobopts, jobopts)
return [v:false, cmd]
endfunction

function! s:yazi_callback(job, data, event, opener) abort
if filereadable(s:yazi_tmpfile)
let filenames = readfile(s:yazi_tmpfile)
if !empty(filenames)
if has('nvim')
call floaterm#window#hide(bufnr('%'))
endif
let locations = []
for filename in filenames
let dict = {'filename': fnamemodify(filename, ':p')}
call add(locations, dict)
endfor
call floaterm#util#open(locations, a:opener)
endif
endif
endfunction

0 comments on commit 6e81602

Please sign in to comment.