initial lualine setup

This commit is contained in:
hoob3rt 2020-12-30 15:48:51 +01:00
parent 2c24d623dc
commit fa6aa3c324
14 changed files with 413 additions and 0 deletions

4
.luacheckrc Normal file
View File

@ -0,0 +1,4 @@
globals = {
"vim",
"vimp",
}

108
lua/lualine.lua Normal file
View File

@ -0,0 +1,108 @@
local utils = require('lualine.utils')
local highlight = require('lualine.highlight')
local M = { }
M.theme = 'gruvbox'
M.separator = '|'
M.sections = {
lualine_a = { 'mode' },
lualine_b = { 'branch' },
lualine_c = { 'filename' },
lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' },
lualine_z = { 'location' },
lualine_diagnostics = { }
}
M.inactiveSections = {
lualine_a = { },
lualine_b = { },
lualine_c = { 'filename' },
lualine_x = { 'location' },
lualine_y = { },
lualine_z = { }
}
M.extensions = {
}
local function loadComponents()
local function loadSections(sections)
for _, section in pairs(sections) do
for index, component in pairs(section) do
if type(component) == 'string' then
section[index] = require('lualine.components.' .. component)
end
end
end
end
loadSections(M.sections)
loadSections(M.inactiveSections)
end
local function loadExtensions()
for _, extension in pairs(M.extensions) do
if type(extension) == 'string' then
require('lualine.components.extensions.' .. extension).loadExtension()
end
if type(extension) == 'table' then
extension.loadExtension()
end
if type(extension) == 'function' then
extension()
end
end
end
local function StatusLine(isFocused)
local sections = M.sections
if not isFocused then
sections = M.inactiveSections
end
if type(M.theme) == 'string' then
M.theme = utils.setTheme(M.theme)
highlight.createHighlightGroups(M.theme)
end
local status = ''
if sections.lualine_a ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_a')
status = status .. utils.drawSection(sections.lualine_a, M.separator)
end
if sections.lualine_b ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_b')
status = status .. utils.drawSection(sections.lualine_b, M.separator)
end
if sections.lualine_c ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_c')
status = status .. utils.drawSection(sections.lualine_c, M.separator)
end
status = status .. [[%=]]
if sections.lualine_x ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_c')
status = status .. utils.drawSection(sections.lualine_x, M.separator)
end
if sections.lualine_y ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_b')
status = status .. utils.drawSection(sections.lualine_y, M.separator)
end
if sections.lualine_z ~= nil then
status = status .. highlight.formatHighlight(isFocused, 'lualine_a')
status = status .. utils.drawSection(sections.lualine_z, M.separator)
end
return status
end
function M.status()
loadComponents()
loadExtensions()
_G.statusline = StatusLine
vim.cmd([[autocmd WinEnter,BufEnter * setlocal statusline=%!v:lua.statusline(1)]])
vim.cmd([[autocmd WinLeave,BufLeave * setlocal statusline=%!v:lua.statusline()]])
end
M.status()
return M

View File

@ -0,0 +1,25 @@
local function Branch()
local branch = vim.fn.systemlist(
'cd '..vim.fn.expand('%:p:h:S')..' 2>/dev/null && git status --porcelain -b 2>/dev/null')[1]
if not branch or #branch == 0 then
return ''
end
branch = branch:gsub([[^## No commits yet on (%w+)$]], '%1')
branch = branch:gsub([[^##%s+(%w+).*$]], '%1')
local ok,devicons = pcall(require,'nvim-web-devicons')
if ok then
local icon = devicons.get_icon('git')
if icon ~= nil then
return icon .. ' ' .. branch
end
return branch
end
ok = (vim.fn.exists('*WebDevIconsGetFileTypeSymbol'))
if ok then
local icon = ''
return icon .. ' ' .. branch
end
return branch
end
return Branch

View File

@ -0,0 +1,6 @@
local function Encoding()
local encoding = [[%{strlen(&fenc)?&fenc:&enc}]]
return encoding
end
return Encoding

View File

@ -0,0 +1,17 @@
local function fzfStatusline()
vim.cmd([[hi clear fzf1]])
vim.cmd([[hi link fzf1 lualine_a_normal]])
vim.cmd([[hi clear fzf2]])
vim.cmd([[hi link fzf2 lualine_c_normal]])
return ([[%#fzf1# FZF %#fzf2#]])
end
local function loadExtension()
_G.fzfStatusline = fzfStatusline
vim.cmd(([[autocmd! User FzfStatusLine setlocal statusline=%!v:lua.fzfStatusline()]]))
end
return {
loadExtension = loadExtension
}

View File

@ -0,0 +1,6 @@
local function FileFormat()
local fileformat = [[%{&ff}]]
return fileformat
end
return FileFormat

View File

@ -0,0 +1,5 @@
local function FileName()
return [[%t %m]]
end
return FileName

View File

@ -0,0 +1,23 @@
local function Filetype()
local filetype = vim.bo.filetype
if filetype:len() > 0 then
local ok,devicons = pcall(require,'nvim-web-devicons')
if ok then
local f_name,f_extension = vim.fn.expand('%:t'),vim.fn.expand('%:e')
local icon = devicons.get_icon(f_name,f_extension)
if icon ~= nil then
return icon .. ' ' .. filetype
end
return filetype
end
ok = (vim.fn.exists('*WebDevIconsGetFileTypeSymbol'))
if ok then
local icon = vim.call('WebDevIconsGetFileTypeSymbol')
return icon .. ' ' .. filetype
end
return filetype
end
return ''
end
return Filetype

View File

@ -0,0 +1,5 @@
local function Location()
return[[%3l:%-2c]]
end
return Location

View File

@ -0,0 +1,18 @@
local function Mode()
local mode_map = {
['__'] = '------',
['n'] = 'NORMAL',
['i'] = 'INSERT',
['v'] = 'VISUAL',
['V'] = 'V-LINE',
[''] = 'V-BLOCK',
['R'] = 'REPLACE',
['r'] = 'REPLACE',
['Rv'] = 'V-REPLACE',
['c'] = 'COMMAND',
['t'] = 'TERMINAL',
}
return mode_map[vim.fn.mode()]
end
return Mode

View File

@ -0,0 +1,5 @@
local function Progress()
return [[%3P]]
end
return Progress

47
lua/lualine/highlight.lua Normal file
View File

@ -0,0 +1,47 @@
local M = { }
local function highlight (name, foreground, background, special)
if special == nil then
special = 'none'
end
local command = 'highlight '
command = command .. name .. ' '
command = command .. 'guifg=' .. foreground .. ' '
command = command .. 'guibg=' .. background .. ' '
if special then
command = command .. 'gui=' .. special .. ' '
end
return command
end
function M.createHighlightGroups(theme)
for mode, sections in pairs(theme) do
for section, colorscheme in pairs(sections) do
if section == 'a' then
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg ,'bold'))
else
vim.cmd(highlight('lualine_' .. section .. '_' .. mode, colorscheme.fg, colorscheme.bg ))
end
end
end
end
function M.formatHighlight(isFocused, highlighGroup)
local mode = require('lualine.components.mode')()
highlighGroup = [[%#]] .. highlighGroup
if not isFocused then
highlighGroup = highlighGroup .. [[_inactive]]
else
if mode == 'V-BLOCK' or mode == 'V-LINE' then
highlighGroup = highlighGroup .. '_visual'
elseif mode == 'V-REPLACE' then
highlighGroup = highlighGroup .. '_replace'
else
highlighGroup = highlighGroup .. '_' .. mode:lower()
end
end
highlighGroup = highlighGroup .. [[#]]
return highlighGroup
end
return M

View File

@ -0,0 +1,111 @@
local M = { }
local Colors = {
black = "#282828",
white = '#ebdbb2',
red = '#fb4934',
green = '#b8bb26',
blue = '#83a598',
yellow = '#fe8019',
gray = '#a89984',
darkgray = '#3c3836',
lightgray = '#504945',
inactivegray = '#7c6f64',
}
M.normal = {
a = {
bg = Colors.gray,
fg = Colors.black,
},
b = {
bg = Colors.lightgray,
fg = Colors.white,
},
c = {
bg = Colors.darkgray,
fg = Colors.gray
}
}
M.insert = {
a = {
bg = Colors.blue,
fg = Colors.black,
},
b = {
bg = Colors.lightgray,
fg = Colors.white,
},
c = {
bg = Colors.lightgray,
fg = Colors.white
}
}
M.visual = {
a = {
bg = Colors.yellow,
fg = Colors.black,
},
b = {
bg = Colors.lightgray,
fg = Colors.white,
},
c = {
bg = Colors.inactivegray,
fg = Colors.black
},
}
M.replace = {
a = {
bg = Colors.red,
fg = Colors.black,
},
b = {
bg = Colors.lightgray,
fg = Colors.white,
},
c = {
bg = Colors.black,
fg = Colors.white
},
}
M.command = {
a = {
bg = Colors.green,
fg = Colors.black,
},
b = {
bg = Colors.lightgray,
fg = Colors.white,
},
c = {
bg = Colors.inactivegray,
fg = Colors.black
},
}
M.terminal = M.normal
M.inactive = {
a = {
bg = Colors.darkgray,
fg = Colors.gray,
},
b = {
bg = Colors.darkgray,
fg = Colors.gray,
},
c = {
bg = Colors.darkgray,
fg = Colors.gray
},
}
return M

33
lua/lualine/utils.lua Normal file
View File

@ -0,0 +1,33 @@
local M = { }
function M.setTheme(theme)
return require('lualine.themes.'..theme)
end
function M.drawSection(section, separator)
local status = ''
for index, statusFunction in pairs(section) do
local localstatus = statusFunction()
if localstatus:len() > 0 then
if separator:len() > 0 then
if index > 1 then
status = status .. separator .. ' '
end
status = status .. localstatus
status = status .. ' '
else
status = status .. localstatus
status = status .. ' '
end
end
end
if status:len() > 0 then
if separator:len() > 0 and table.maxn(section) > 1 then
return ' ' .. status .. ' '
end
return ' ' .. status
end
return ''
end
return M