fern.vim 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. " MIT License. Copyright (c) 2013-2021
  2. " Plugin: https://github.com/lambdalisue/fern.vim
  3. " vim: et ts=2 sts=2 sw=2
  4. scriptencoding utf-8
  5. if !get(g:, 'loaded_fern', 0)
  6. finish
  7. endif
  8. function! airline#extensions#fern#apply_active(...) abort
  9. " check if current buffer is both fern and active
  10. if (&ft =~# 'fern') && a:2.active ==# '1'
  11. call airline#extensions#fern#configure_sections(a:1, a:2)
  12. return 1
  13. endif
  14. endfunction
  15. function! airline#extensions#fern#apply_inactive(...) abort
  16. " check if referenced buffer is both fern and inactive
  17. if getbufvar(a:2.bufnr, '&filetype') ==# 'fern' && a:2.active ==# '0'
  18. call airline#extensions#fern#configure_sections(a:1, a:2)
  19. return 1
  20. endif
  21. endfunction
  22. function! airline#extensions#fern#configure_sections(win, context) abort
  23. let spc = g:airline_symbols.space
  24. let fri = fern#fri#parse(bufname(a:context.bufnr))
  25. let abspath = substitute(fri.path, 'file://', '', '')
  26. call a:win.add_section('airline_a', spc.'fern'.spc)
  27. if exists('*airline#extensions#branch#get_head')
  28. " because fern navigation changes an internal _fri_ and not the working directory
  29. " we need to give it some help so the branch name gets updated
  30. execute 'lcd' abspath
  31. call a:win.add_section('airline_b', spc.'%{airline#extensions#branch#get_head()}'.spc)
  32. else
  33. call a:win.add_section('airline_b', '')
  34. endif
  35. if !(fri.authority =~# '^drawer')
  36. call a:win.add_section('airline_c', spc.fnamemodify(abspath, ':~'))
  37. call a:win.split()
  38. if len(get(g:, 'fern#comparators', {}))
  39. call a:win.add_section('airline_y', spc.'%{fern#comparator}'.spc)
  40. endif
  41. endif
  42. endfunction
  43. function! airline#extensions#fern#init(ext) abort
  44. let g:fern_force_overwrite_statusline = 0
  45. call a:ext.add_statusline_func('airline#extensions#fern#apply_active')
  46. call a:ext.add_inactive_statusline_func('airline#extensions#fern#apply_inactive')
  47. endfunction