Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option on how to get a devicon #1133

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ sections = {
'filetype',
colored = true, -- Displays filetype icon in color if set to true
icon_only = false, -- Display only an icon for filetype
get_icon_by = 'filename', -- Method to get devicon ('filetype' or 'filename')
icon = { align = 'right' }, -- Display filetype icon on the right hand side
-- icon = {'X', align='right'}
-- Icon string ^ in table is ignored in filetype component
Expand Down
12 changes: 10 additions & 2 deletions lua/lualine/components/filetype.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ local M = lualine_require.require('lualine.component'):extend()
local default_options = {
colored = true,
icon_only = false,
get_icon_by = 'filename',
}

function M:init(options)
Expand All @@ -31,9 +32,16 @@ function M:apply_icon()
local icon, icon_highlight_group
local ok, devicons = pcall(require, 'nvim-web-devicons')
if ok then
icon, icon_highlight_group = devicons.get_icon(vim.fn.expand('%:t'))
if icon == nil then
if self.options.get_icon_by == 'filetype' then
icon, icon_highlight_group = devicons.get_icon_by_filetype(vim.bo.filetype)
if icon == nil then
icon, icon_highlight_group = devicons.get_icon(vim.fn.expand('%:t'))
end
else
icon, icon_highlight_group = devicons.get_icon(vim.fn.expand('%:t'))
if icon == nil then
icon, icon_highlight_group = devicons.get_icon_by_filetype(vim.bo.filetype)
end
end

if icon == nil and icon_highlight_group == nil then
Expand Down
Loading