all repos — dotfiles @ 9561d9bd704d8c05db90e5539824f73cd32f6860

my *nix dotfiles

config/nvim/lua/statusline.lua (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
-- set highlights for statusline sections
vim.api.nvim_exec(
[[
	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 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()
  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
  end
end

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_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',
  '%#Blanks#',
  '%m',
  '%#SecondaryBlock#',
  git_branch(),
  '%=',
  '%#SecondaryBlock#',
  '%l,%c ',
  '%#PrimaryBlock#',
  '%{&filetype}',
}

vim.opt_global.statusline = table.concat(stl)