nvim: Statusline shenanigans
Anirudh Oppiliappan x@icyphox.sh
Thu, 08 Jul 2021 16:29:24 +0530
3 files changed,
24 insertions(+),
61 deletions(-)
M
config/nvim/lua/settings.lua
→
config/nvim/lua/settings.lua
@@ -1,4 +1,4 @@
-u = require('utils') +local u = require('utils') local o = vim.opt local g = vim.g@@ -64,6 +64,10 @@ o.wrap = false
-- buffer-local options o.expandtab = true + +-- set statusline +stl = require('statusline.line') +o.statusline = '%!luaeval("stl.statusline()")' -- augroups don't have an interface yet u.create_augroup({
M
config/nvim/lua/statusline/git.lua
→
config/nvim/lua/statusline/git.lua
@@ -1,9 +1,5 @@
local M = {} -local git_branch -local clean = '•' -local dirty = '×' - local sep = package.config:sub(1,1) local function find_git_dir()@@ -21,8 +17,8 @@ if f_head then
local HEAD = f_head:read() f_head:close() local branch = HEAD:match('ref: refs/heads/(.+)$') - if branch then git_branch = branch - else git_branch = HEAD:sub(1,7) end + if branch then M.git_branch = branch + else M.git_branch = HEAD:sub(1,7) end end return nil end@@ -41,34 +37,7 @@ watch_head()
end)) else -- set to nil when git dir was not found - git_branch = nil - end -end - -function M.branch() - if not git_branch or #git_branch == 0 then return '' end - return git_branch -end - -local function is_clean() - if M.in_git then - local handle = io.popen('git status --porcelain 2> /dev/null') - local status = handle:read('*a') - - if status ~= '' then return false end - return true - end - return nil -end - --- clean or dirty -function M.status() - if M.in_git then - if is_clean() then - return '%#GitClean#' .. clean - else - return '%#GitDirty#' .. dirty - end + M.git_branch = nil end end
M
config/nvim/lua/statusline/line.lua
→
config/nvim/lua/statusline/line.lua
@@ -1,5 +1,6 @@
local git = require('statusline.git') local utils = require('utils') +local M = {} -- set highlights for statusline sections vim.api.nvim_exec(@@ -11,32 +12,21 @@ hi GitClean ctermfg=02 ctermbg=00
hi GitDirty ctermfg=01 ctermbg=00 ]], false) -local git_info -if git.in_git then - git_info = string.format(' %s %s', git.branch(), git.status()) -else - git_info = '' -end - - -local stl = { - '%#PrimaryBlock#', - '%f', - '%#Blanks#', - '%m', - '%#SecondaryBlock#', - git_info, - '%=', - '%#SecondaryBlock#', - '%l,%c ', - '%#PrimaryBlock#', - '%{&filetype}', -} - -_G.statusline = function() +function M.statusline() + local stl = { + '%#PrimaryBlock#', + '%f', + '%#Blanks#', + '%m', + '%#SecondaryBlock#', + ' '..git.git_branch, + '%=', + '%#SecondaryBlock#', + '%l,%c ', + '%#PrimaryBlock#', + '%{&filetype}', + } return table.concat(stl) end -utils.create_augroup({ - { 'WinEnter,BufEnter', '*', 'setlocal', 'statusline=%!v:lua.statusline()' }, -}, 'Statusline') +return M