all repos — dotfiles @ fcd2a5a95b5ca3254f664d970d49cb4554b90d42

my *nix dotfiles

Check if we're in git
Anirudh Oppiliappan x@icyphox.sh
Sun, 06 Jun 2021 17:09:32 +0530
commit

fcd2a5a95b5ca3254f664d970d49cb4554b90d42

parent

f9c9735ee6e2e199e5c35a6e70027bd438164aa8

1 files changed, 32 insertions(+), 19 deletions(-)

jump to
M config/nvim/lua/statusline.luaconfig/nvim/lua/statusline.lua

@@ -11,34 +11,48 @@

local clean = '•' local dirty = '×' +local function are_we_in_git() + local handle = io.popen('git rev-parse --is-inside-work-tree 2> /dev/null') + local out = handle:read('*a'):gsub('\n', '') + if out == 'true' then + in_git = true + end +end + local function is_clean() - local handle = io.popen('git status --porcelain 2> /dev/null') - local status = handle:read('*a') + if 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 + if status ~= '' then return false end + return true + end 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 - return out - else - return '' +local function git_sym() + if in_git then + if is_clean() then + return ' %#GitClean#' .. clean + else + return ' %#GitDirty#' .. dirty + end end end -local function git_sym() - if is_clean() then - return ' %#GitClean#' .. clean - else - return ' %#GitDirty#' .. dirty +local function git_branch() + if in_git then + 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 .. git_sym() + return out + end end + return '' end +are_we_in_git() local stl = { '%#PrimaryBlock#', '%f',

@@ -46,7 +60,6 @@ '%#Blanks#',

'%m', '%#SecondaryBlock#', git_branch(), - git_sym(), '%=', '%#SecondaryBlock#', '%l,%c ',