Add git clean and dirty symbols to statusline
Anirudh Oppiliappan x@icyphox.sh
Sun, 06 Jun 2021 11:16:21 +0530
2 files changed,
20 insertions(+),
5 deletions(-)
M
config/nvim/init.lua
→
config/nvim/init.lua
@@ -23,7 +23,7 @@ require('statusline')
-- lsp setup -- require('lsp.yaml') shits too noisy -require('lsp.lua') +-- require('lsp.lua') it's horrible require('lsp.python') require('lsp.go')
M
config/nvim/lua/statusline.lua
→
config/nvim/lua/statusline.lua
@@ -4,14 +4,19 @@ [[
hi PrimaryBlock ctermfg=06 ctermbg=00 hi SecondaryBlock ctermfg=07 ctermbg=00 hi Blanks ctermfg=08 ctermbg=00 + hi GitClean ctermfg=02 ctermbg=00 + hi GitDirty ctermfg=01 ctermbg=00 ]], false) -local function clean_or_dirty() +local clean = '•' +local dirty = '×' + +local function is_clean() local handle = io.popen('git status --porcelain 2> /dev/null') local status = handle:read('*a') - if status ~= '' then return '*' end - return status + if status ~= '' then return false end + return true end local function git_branch()@@ -19,19 +24,29 @@ local handle = io.popen('git branch --show-current 2> /dev/null')
local branch = handle:read('*a'):gsub('\n', '') local rc = { handle:close() } if rc[1] then - local out = ' ' .. branch .. clean_or_dirty() + local out = ' ' .. branch return out else return '' end end +local function git_sym() + if is_clean() then + return ' %#GitClean#' .. clean + else + return ' %#GitDirty#' .. dirty + end +end + local stl = { '%#PrimaryBlock#', '%f', '%#Blanks#', '%m', '%#SecondaryBlock#', + git_branch(), + git_sym(), '%=', '%#SecondaryBlock#', '%l,%c ',