aboutsummaryrefslogtreecommitdiff
path: root/neovim/.config/nvim/lua/dyamon/tabline.lua
blob: a6590e4f673889d5267e7347e6a7152bd02743b4 (plain) (blame)
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
--- Personal lua config files for NeoVim.
--  Last Changed: 2019-01-27
--  Author: Federico Igne <git@federicoigne.com>
--  License: This file is placed in the public domain.

-- Use name in `t:tablabel` or fall back to the name of the current
-- working directory.
local function tablabel(i, t)
  local ok, label = pcall(vim.api.nvim_tabpage_get_var, t, 'tablabel')
  if not ok then
    label = vim.fn.fnamemodify(vim.fn.getcwd(-1, i), ':t')
  end
  return label
end

--- Generate simple tabline that supports custom naming.
--
-- To set the name for a specific tab run
--
--      :let t:tablabel = <name>
--
-- This variable persists across sessions
local function tabline()
  local line = ''
  local current = vim.api.nvim_get_current_tabpage()
  local tabpages = vim.api.nvim_list_tabpages()
  for i, t in pairs(tabpages) do
    local modified = false
    local windows = vim.api.nvim_tabpage_list_wins(t)
    local nwin = 0
    for _,w in pairs(windows) do
      if vim.api.nvim_buf_get_option(vim.api.nvim_win_get_buf(w), 'modified') then
          modified = true
      end
      nwin = nwin + 1
    end
    if t == current then
      if modified then
        line = line .. '%4*'
      else
        line = line .. '%3*'
      end
    else
      line = line .. '%#TabLine#'
    end
    -- Start tabpage label with number indicator
    line = line .. '%' .. i .. 'T ' .. i
    -- Modified label
    if modified then
      line = line .. '+'
    end
    -- Get tabpage label
    line = line .. ' '
    if t == current then
      line = line .. '▏'
    end
    line = line .. tablabel(i, t) .. ' [' .. nwin .. '] '
  end
  -- Fill with TabLineFill and reset tabpage label
  line = line .. '%#TabLineFill#%T'
  return line
end

return tabline