all repos — dotfiles @ 2c00620ef710e80a5702621b075274fdfd3a6e2b

my *nix dotfiles

nvim: Clean up git_branch()
Anirudh Oppiliappan x@icyphox.sh
Tue, 02 Mar 2021 08:30:37 +0530
commit

2c00620ef710e80a5702621b075274fdfd3a6e2b

parent

63c9c5914dfbf8d1fe931b0199dea3dfa5a520ce

2 files changed, 16 insertions(+), 9 deletions(-)

jump to
M config/nvim/lua/maps.luaconfig/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.luaconfig/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 ',