| 1 |
-- Eviline config for lualine |
| 2 |
-- Author: shadmansaleh |
| 3 |
-- Credit: glepnir |
| 4 |
local lualine = require('lualine') |
| 5 |
|
| 6 |
-- Color table for highlights |
| 7 |
-- stylua: ignore |
| 8 |
local colors = { |
| 9 |
bg = '#202328', |
| 10 |
fg = '#bbc2cf', |
| 11 |
yellow = '#ECBE7B', |
| 12 |
cyan = '#008080', |
| 13 |
darkblue = '#081633', |
| 14 |
green = '#98be65', |
| 15 |
orange = '#FF8800', |
| 16 |
violet = '#a9a1e1', |
| 17 |
magenta = '#c678dd', |
| 18 |
blue = '#51afef', |
| 19 |
red = '#ec5f67', |
| 20 |
} |
| 21 |
|
| 22 |
local conditions = { |
| 23 |
buffer_not_empty = function() |
| 24 |
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1 |
| 25 |
end, |
| 26 |
hide_in_width = function() |
| 27 |
return vim.fn.winwidth(0) > 80 |
| 28 |
end, |
| 29 |
check_git_workspace = function() |
| 30 |
local filepath = vim.fn.expand('%:p:h') |
| 31 |
local gitdir = vim.fn.finddir('.git', filepath .. ';') |
| 32 |
return gitdir and #gitdir > 0 and #gitdir < #filepath |
| 33 |
end, |
| 34 |
} |
| 35 |
|
| 36 |
-- Config |
| 37 |
local config = { |
| 38 |
options = { |
| 39 |
-- Disable sections and component separators |
| 40 |
component_separators = '', |
| 41 |
section_separators = '', |
| 42 |
theme = { |
| 43 |
-- We are going to use lualine_c an lualine_x as left and |
| 44 |
-- right section. Both are highlighted by c theme . So we |
| 45 |
-- are just setting default looks o statusline |
| 46 |
normal = { c = { fg = colors.fg, bg = colors.bg } }, |
| 47 |
inactive = { c = { fg = colors.fg, bg = colors.bg } }, |
| 48 |
}, |
| 49 |
}, |
| 50 |
sections = { |
| 51 |
-- these are to remove the defaults |
| 52 |
lualine_a = {}, |
| 53 |
lualine_b = {}, |
| 54 |
lualine_y = {}, |
| 55 |
lualine_z = {}, |
| 56 |
-- These will be filled later |
| 57 |
lualine_c = {}, |
| 58 |
lualine_x = {}, |
| 59 |
}, |
| 60 |
inactive_sections = { |
| 61 |
-- these are to remove the defaults |
| 62 |
lualine_a = {}, |
| 63 |
lualine_b = {}, |
| 64 |
lualine_y = {}, |
| 65 |
lualine_z = {}, |
| 66 |
lualine_c = {}, |
| 67 |
lualine_x = {}, |
| 68 |
}, |
| 69 |
} |
| 70 |
|
| 71 |
-- Inserts a component in lualine_c at left section |
| 72 |
local function ins_left(component) |
| 73 |
table.insert(config.sections.lualine_c, component) |
| 74 |
end |
| 75 |
|
| 76 |
-- Inserts a component in lualine_x at right section |
| 77 |
local function ins_right(component) |
| 78 |
table.insert(config.sections.lualine_x, component) |
| 79 |
end |
| 80 |
|
| 81 |
ins_left { |
| 82 |
function() |
| 83 |
return '▊' |
| 84 |
end, |
| 85 |
color = { fg = colors.blue }, -- Sets highlighting of component |
| 86 |
padding = { left = 0, right = 1 }, -- We don't need space before this |
| 87 |
} |
| 88 |
|
| 89 |
ins_left { |
| 90 |
-- mode component |
| 91 |
function() |
| 92 |
return '' |
| 93 |
end, |
| 94 |
color = function() |
| 95 |
-- auto change color according to neovims mode |
| 96 |
local mode_color = { |
| 97 |
n = colors.red, |
| 98 |
i = colors.green, |
| 99 |
v = colors.blue, |
| 100 |
[''] = colors.blue, |
| 101 |
V = colors.blue, |
| 102 |
c = colors.magenta, |
| 103 |
no = colors.red, |
| 104 |
s = colors.orange, |
| 105 |
S = colors.orange, |
| 106 |
[''] = colors.orange, |
| 107 |
ic = colors.yellow, |
| 108 |
R = colors.violet, |
| 109 |
Rv = colors.violet, |
| 110 |
cv = colors.red, |
| 111 |
ce = colors.red, |
| 112 |
r = colors.cyan, |
| 113 |
rm = colors.cyan, |
| 114 |
['r?'] = colors.cyan, |
| 115 |
['!'] = colors.red, |
| 116 |
t = colors.red, |
| 117 |
} |
| 118 |
return { fg = mode_color[vim.fn.mode()] } |
| 119 |
end, |
| 120 |
padding = { right = 1 }, |
| 121 |
} |
| 122 |
|
| 123 |
ins_left { |
| 124 |
-- filesize component |
| 125 |
'filesize', |
| 126 |
cond = conditions.buffer_not_empty, |
| 127 |
} |
| 128 |
|
| 129 |
ins_left { |
| 130 |
'filename', |
| 131 |
cond = conditions.buffer_not_empty, |
| 132 |
color = { fg = colors.magenta, gui = 'bold' }, |
| 133 |
} |
| 134 |
|
| 135 |
ins_left { 'location' } |
| 136 |
|
| 137 |
ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } } |
| 138 |
|
| 139 |
ins_left { |
| 140 |
'diagnostics', |
| 141 |
sources = { 'nvim_diagnostic' }, |
| 142 |
symbols = { error = ' ', warn = ' ', info = ' ' }, |
| 143 |
diagnostics_color = { |
| 144 |
error = { fg = colors.red }, |
| 145 |
warn = { fg = colors.yellow }, |
| 146 |
info = { fg = colors.cyan }, |
| 147 |
}, |
| 148 |
} |
| 149 |
|
| 150 |
-- Insert mid section. You can make any number of sections in neovim :) |
| 151 |
-- for lualine it's any number greater then 2 |
| 152 |
ins_left { |
| 153 |
function() |
| 154 |
return '%=' |
| 155 |
end, |
| 156 |
} |
| 157 |
|
| 158 |
ins_left { |
| 159 |
-- Lsp server name . |
| 160 |
function() |
| 161 |
local msg = 'No Active Lsp' |
| 162 |
local buf_ft = vim.api.nvim_get_option_value('filetype', { buf = 0 }) |
| 163 |
local clients = vim.lsp.get_clients() |
| 164 |
if next(clients) == nil then |
| 165 |
return msg |
| 166 |
end |
| 167 |
for _, client in ipairs(clients) do |
| 168 |
local filetypes = client.config.filetypes |
| 169 |
if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then |
| 170 |
return client.name |
| 171 |
end |
| 172 |
end |
| 173 |
return msg |
| 174 |
end, |
| 175 |
icon = ' LSP:', |
| 176 |
color = { fg = '#ffffff', gui = 'bold' }, |
| 177 |
} |
| 178 |
|
| 179 |
-- Add components to right sections |
| 180 |
ins_right { |
| 181 |
'o:encoding', -- option component same as &encoding in viml |
| 182 |
fmt = string.upper, -- I'm not sure why it's upper case either ;) |
| 183 |
cond = conditions.hide_in_width, |
| 184 |
color = { fg = colors.green, gui = 'bold' }, |
| 185 |
} |
| 186 |
|
| 187 |
ins_right { |
| 188 |
'fileformat', |
| 189 |
fmt = string.upper, |
| 190 |
icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh |
| 191 |
color = { fg = colors.green, gui = 'bold' }, |
| 192 |
} |
| 193 |
|
| 194 |
ins_right { |
| 195 |
'branch', |
| 196 |
icon = '', |
| 197 |
color = { fg = colors.violet, gui = 'bold' }, |
| 198 |
} |
| 199 |
|
| 200 |
ins_right { |
| 201 |
'diff', |
| 202 |
-- Is it me or the symbol for modified us really weird |
| 203 |
symbols = { added = ' ', modified = ' ', removed = ' ' }, |
| 204 |
diff_color = { |
| 205 |
added = { fg = colors.green }, |
| 206 |
modified = { fg = colors.orange }, |
| 207 |
removed = { fg = colors.red }, |
| 208 |
}, |
| 209 |
cond = conditions.hide_in_width, |
| 210 |
} |
| 211 |
|
| 212 |
ins_right { |
| 213 |
function() |
| 214 |
return '▊' |
| 215 |
end, |
| 216 |
color = { fg = colors.blue }, |
| 217 |
padding = { left = 1 }, |
| 218 |
} |
| 219 |
|
| 220 |
-- Now don't forget to initialize lualine |
| 221 |
lualine.setup(config) |