vim-nerdfont icon indicating copy to clipboard operation
vim-nerdfont copied to clipboard

Add API to get an icon from the value of 'filetype'

Open Bakudankun opened this issue 4 years ago • 0 comments

This is a PR for #4.

The g:nerdfont#filetype#defaults was made by the next script and some necessary hand-picking. No docs and tests yet, but I'll add them before very long...

" filetype_icons.vim
" Create a dictionary that maps filetypes to icons by converting path icons.
" Place this file into the project root directory and run the next command:
" vim --clean -S filetype_icons.vim
" Then check g:filetype_icons.

set encoding=utf-8

source ./autoload/nerdfont/path/extension.vim
source ./autoload/nerdfont/path/basename.vim

let g:filetype_icons = {}


function! s:add_filetype_icon(filename, icon)
  execute 'new' fnameescape(a:filename)
  let filetype = &filetype
  quit

  if !has_key(g:filetype_icons, filetype) 
    let g:filetype_icons[filetype] = a:icon
    return
  endif

  " If the filetype is duplicate, make a list to contain all icons
  " for later hand-picking.
  if type(g:filetype_icons[filetype]) == v:t_string
    if g:filetype_icons[filetype] ==# a:icon
      return
    endif

    let g:filetype_icons[filetype] = [g:filetype_icons[filetype]]
  endif

  if index(g:filetype_icons[filetype], a:icon) < 0
    call add(g:filetype_icons[filetype], a:icon)
  endif
endfunction


for [ext, icon] in items(g:nerdfont#path#extension#defaults)
  call s:add_filetype_icon('hoge.' .. ext, icon)
endfor

for [filename, icon] in items(g:nerdfont#path#basename#defaults)
  call s:add_filetype_icon(filename, icon)
endfor

Bakudankun avatar Oct 26 '20 15:10 Bakudankun