--- Personal lua config files for NeoVim. -- Last Changed: 2019-01-27 -- Author: Federico Igne -- License: This file is placed in the public domain. local api = vim.api local cmd = vim.cmd local statusline = {} --- Custom mode flags local mode_flags = { ["n"] = "N", ["v"] = "V", ["V"] = "V·Line", [""] = "V·Block", ["s"] = "S", ["S"] = "S·Line", [""] = "S·Block", ["i"] = "I", ["R"] = "R", ["c"] = "C", ["r"] = "Prompt", ["!"] = "Shell", ["t"] = "T" } --- Custom filetype flags (overrides mode flag) local filetype_flags = { help = 'Help', qf = 'QFix', netrw = 'Netrw', fugitive = 'Gstatus', tagbar = 'TagBar', gitcommit = 'Gcommit' } --- Custom name flags (overrides mode flag) local name_flags = { ['[Grammarous]'] = 'Grammar' } --- Preview flag (overrides mode flag) local preview_flag = { [true] = 'Preview' } --- Get mode flag for current buffer local function modeflag() local label local preview = vim.o.previewwindow local name = api.nvim_buf_get_name(api.nvim_get_current_buf()) local filetype = vim.o.filetype local mode = vim.api.nvim_get_mode().mode:sub(1, 1) return preview_flag[preview] or name_flags[name] or filetype_flags[filetype] or mode_flags[mode] end --- Get formatted filename local function filename() local filename = '' local bufname = vim.fn.expand('%') if bufname:len() == 0 then -- New (empty) buffer filename = "%1*[No Name]%*" elseif bufname:find('^term://.*') then -- Terminal buffer local _,_,pid,cmd = bufname:find('term://.+//(%d+):(.+)') filename = "%1*" .. cmd .. " (" .. pid .. "/" .. vim.o.channel .. ")%*" else -- Other buffers local path = vim.fn.expand('%:h') if path ~= '' and path ~= '.' then filename = "%1*" .. path .. "/%*" end filename = filename .. "%2*%t%*" end return filename end -- Get git information local function gitinfo() local git = '' if vim.fn.exists('*FugitiveHead') then local head = vim.fn.FugitiveHead(8) local status = vim.b.gitsigns_status_dict if head:len() > 0 then git = git .. head .. ' ' end if status and status.added and status.changed and status.removed then git = git .. string.format('(+%d ~%d -%d) ', status.added, status.changed, status.removed) end end return git end -- Return a flag if a session is being tracked function statusline.session() local session = '' if require('dyamon').session.exists() then session = ',s' end if vim.t.this_session then session = ',S' end return session end -- Return file encoding flag if different from default (utf8). function statusline.fileenc() local fileenc = vim.bo.fileencoding if fileenc ~= 'utf-8' and fileenc ~= '' then return ',' .. fileenc else return '' end end -- Return (lowercase) filetype flag function statusline.filetype() local filetype = vim.bo.filetype if filetype ~= '' then return ',' .. filetype else return '' end end local function statusline_focused() local status = '' local accent = "%3*" if vim.bo.modified then accent = "%4*" end status = accent .. " " .. modeflag() .. " %*%< " status = status .. filename() .. "%=" status = status .. gitinfo() --status = status .. zettelstatus() .. " " status = status .. "[%M%R%{v:lua.dyamon.statusline.session()}%{v:lua.dyamon.statusline.fileenc()}%{v:lua.dyamon.statusline.filetype()}]" .. " " status = status .. accent .. " %3l/%L %2c/%2{%len(getline('.'))%} [%P]" --status = status .. " " .. lsp() return status end local function statusline_blurred() return " %<%f%=" end function statusline.update() local current = vim.g.statusline_winid == api.nvim_get_current_win() if current then return statusline_focused() else return statusline_blurred() end end return statusline