all repos — dotfiles @ 6827b3a35248eb01836743006fc9c6b9c543f20f

my *nix dotfiles

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

 1-- set highlights for statusline sections
 2vim.api.nvim_exec(
 3[[
 4	hi PrimaryBlock ctermfg=06 ctermbg=00
 5	hi SecondaryBlock   ctermfg=07 ctermbg=00
 6	hi Blanks   ctermfg=08 ctermbg=00
 7  hi GitClean ctermfg=02 ctermbg=00
 8  hi GitDirty ctermfg=01 ctermbg=00
 9]], false)
10
11local clean = ''
12local dirty = '×'
13
14local function are_we_in_git()
15  local handle = io.popen('git rev-parse --is-inside-work-tree 2> /dev/null')
16  local out = handle:read('*a'):gsub('\n', '')
17  if out == 'true' then
18    in_git = true
19  end
20end
21
22local function is_clean()
23  if in_git then
24    local handle = io.popen('git status --porcelain 2> /dev/null')
25    local status = handle:read('*a')
26
27    if status ~= '' then return false end
28    return true
29  end
30end
31
32local function git_sym()
33  if in_git then
34    if is_clean() then
35      return ' %#GitClean#' .. clean
36    else
37      return ' %#GitDirty#' .. dirty
38    end
39  end
40end
41
42local function git_branch()
43  if in_git then
44    local handle = io.popen('git branch --show-current 2> /dev/null')
45    local branch = handle:read('*a'):gsub('\n', '')
46    local rc = { handle:close() }
47    if rc[1] then
48      local out = ' ' .. branch .. git_sym()
49      return out
50    end
51  end
52    return ''
53end
54
55are_we_in_git()
56local stl = {
57  '%#PrimaryBlock#',
58  '%f',
59  '%#Blanks#',
60  '%m',
61  '%#SecondaryBlock#',
62  git_branch(),
63  '%=',
64  '%#SecondaryBlock#',
65  '%l,%c ',
66  '%#PrimaryBlock#',
67  '%{&filetype}',
68}
69
70vim.opt_global.statusline = table.concat(stl)