nvim: Clean up git_branch()
Anirudh Oppiliappan x@icyphox.sh
Tue, 02 Mar 2021 08:30:37 +0530
2 files changed,
16 insertions(+),
9 deletions(-)
M
config/nvim/lua/maps.lua
→
config/nvim/lua/maps.lua
@@ -82,4 +82,6 @@ " Avoid showing message extra message when using completion
set shortmess+=c ]], false) +map('i', '<Tab>', '<C-n>', options) + return M
M
config/nvim/lua/statusline.lua
→
config/nvim/lua/statusline.lua
@@ -6,28 +6,33 @@ hi SecondaryBlock ctermfg=07 ctermbg=00
hi Blanks ctermfg=08 ctermbg=00 ]], false) -local function git_branch() - local handle = io.popen('git branch --show-current') - local branch = handle:read('*a'):gsub('\n', '') - handle:close() - return branch -end - local function clean_or_dirty() - local handle = io.popen('git status --porcelain') + local handle = io.popen('git status --porcelain 2> /dev/null') local status = handle:read('*a') if status ~= '' then return '*' end return status end +local function git_branch() + 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() + return out + else + return '' + end +end + local stl = { '%#PrimaryBlock#', '%f', '%#Blanks#', '%m', '%#SecondaryBlock#', - ' ' .. git_branch() .. clean_or_dirty(), + git_branch(), '%=', '%#SecondaryBlock#', '%l,%c ',