1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
--[[
Provides :DevIcons command to manage dev-icons.
Usage examples:
Toggle dev icons.
:DevIcons
Toggle individual category.
:DevIcons category
--]]
-- TODO: more fine-grained representation and detailed formatting in format()
local icons = {
types = ' :dir:/, :exe:, :reg:, :link:,| :fifo:,= :sock:',
-- various file names
other = ' ::../::, ::*.sh::',
cxx = ' ::*.hpp,,*.cpp,,*.cc,,*.hh::, ::*.h,,*.c::',
docs = ' ::copying,,license::, ::.git/,,*.git/::/',
ebooks = ' ::*.epub,,*.fb2,,*.djvu::, ::*.pdf::',
xml = ' ::*.htm,,*.html,,*.shtml,,*.xhtml,,*.xml::',
archives = ' ::*.7z,,*.ace,,*.arj,,*.bz2,,*.cpio,,*.deb,,*.dz,,*.gz,,'..
'*.jar,,*.lzh,,*.lzma,,*.rar,,*.rpm,,*.rz,,*.tar,,*.taz,,'..
'*.tb2,,*.tbz,,*.tbz2,,*.tgz,,*.tlz,,*.trz,,*.txz,,*.tz,,'..
'*.tz2,,*.xz,,*.z,,*.zip,,*.zoo::',
images = ' ::*.bmp,,*.gif,,*.jpeg,,*.jpg,,*.ico,,*.png,,*.ppm,,*.svg,,'..
'*.svgz,,*.tga,,*.tif,,*.tiff,,*.xbm,,*.xcf,,*.xpm,,*.xspf,,'..
'*.xwd::',
audio = ' ::*.aac,,*.anx,,*.asf,,*.au,,*.axa,,*.flac,,*.m2a,,*.m4a,,'..
'*.mid,,*.midi,,*.mp3,,*.mpc,,*.oga,,*.ogg,,*.ogx,,*.ra,,'..
'*.ram,,*.rm,,*.spx,,*.wav,,*.wma,,*.ac3::',
media = ' ::*.avi,,*.ts,,*.axv,,*.divx,,*.m2v,,*.m4p,,*.m4v,,.mka,,'..
'*.mkv,,*.mov,,*.mp4,,*.flv,,*.mp4v,,*.mpeg,,*.mpg,,*.nuv,,'..
'*.ogv,,*.pbm,,*.pgm,,*.qt,,*.vob,,*.wmv,,*.xvid,,*.webm::',
office = ' ::*.doc,,*.docx::, ::*.xls,,*.xlsm,,*.xlsx::,'..
' ::*.pptx,,*.ppt::',
}
local active = false
local original_classify
local categories = {}
for key, _ in pairs(icons) do
categories[key] = true
end
local function format()
local formatted = ''
for key, value in pairs(icons) do
if categories[key] then
formatted = formatted..value..','
end
end
return formatted
end
local function toggle()
if active then
vifm.opts.global.classify = original_classify
else
original_classify = vifm.opts.global.classify
vifm.opts.global.classify = format()
end
active = not active
end
local function devicons(info)
if #info.argv == 0 then
toggle()
return
end
category = info.argv[1]
local enabled = categories[category]
if enabled == nil then
vifm.sb.error('Unknown category: '..category)
return
end
categories[category] = not enabled
if active then
vifm.opts.global.classify = format()
end
end
local function complete_devicons(info)
local prefix = info.arg
local prefix_len = prefix:len()
local matches = {}
for key, _ in pairs(categories) do
if key:sub(0, prefix_len) == prefix then
matches[#matches + 1] = key
end
end
return { matches = matches }
end
-- this does NOT overwrite pre-existing user command
local added = vifm.cmds.add {
name = "DevIcons",
description = "use iconic font to simulate icons",
handler = devicons,
complete = complete_devicons,
maxargs = 1,
}
if not added then
vifm.sb.error("Failed to register :DevIcons")
end
-- enable icons on startup
toggle()
return {}
|