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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
--- 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.
local api = vim.api
local cmd = vim.cmd
local statusline = {}
--- Custom mode flags
local mode_flags = {
["n"] = "N",
["v"] = "V",
["V"] = "V·Line",
[""] = "V·Block",
["s"] = "S",
["S"] = "S·Line",
[""] = "S·Block",
["i"] = "I",
["R"] = "R",
["c"] = "C",
["r"] = "Prompt",
["!"] = "Shell",
["t"] = "T"
}
--- Custom filetype flags (overrides mode flag)
local filetype_flags = {
help = 'Help',
qf = 'QFix',
netrw = 'Netrw',
fugitive = 'Gstatus',
tagbar = 'TagBar',
gitcommit = 'Gcommit'
}
--- Custom name flags (overrides mode flag)
local name_flags = {
['[Grammarous]'] = 'Grammar'
}
--- Preview flag (overrides mode flag)
local preview_flag = {
[true] = 'Preview'
}
--- Get mode flag for current buffer
local function modeflag()
local label
local preview = vim.o.previewwindow
local name = api.nvim_buf_get_name(api.nvim_get_current_buf())
local filetype = vim.o.filetype
local mode = vim.api.nvim_get_mode().mode:sub(1, 1)
return preview_flag[preview] or name_flags[name] or filetype_flags[filetype] or mode_flags[mode]
end
--- Get formatted filename
local function filename()
local filename = ''
local bufname = vim.fn.expand('%')
if bufname:len() == 0 then
-- New (empty) buffer
filename = "%1*[No Name]%*"
elseif bufname:find('^term://.*') then
-- Terminal buffer
local _,_,pid,cmd = bufname:find('term://.+//(%d+):(.+)')
filename = "%1*" .. cmd .. " (" .. pid .. "/" .. vim.o.channel .. ")%*"
else
-- Other buffers
local path = vim.fn.expand('%:h')
if path ~= '' and path ~= '.' then
filename = "%1*" .. path .. "/%*"
end
filename = filename .. "%2*%t%*"
end
return filename
end
-- Get git information
local function gitinfo()
local git = ''
if vim.fn.exists('*FugitiveHead') then
local head = vim.fn.FugitiveHead(8)
local status = vim.b.gitsigns_status_dict
if head:len() > 0 then
git = git .. head .. ' '
end
if status and status.added and status.changed and status.removed then
git = git .. string.format('(+%d ~%d -%d) ', status.added, status.changed, status.removed)
end
end
return git
end
-- Return a flag if a session is being tracked
function statusline.session()
local session = ''
if require('dyamon').session.exists() then
session = ',s'
end
if vim.t.this_session then
session = ',S'
end
return session
end
-- Return file encoding flag if different from default (utf8).
function statusline.fileenc()
local fileenc = vim.bo.fileencoding
if fileenc ~= 'utf-8' and fileenc ~= '' then
return ',' .. fileenc
else
return ''
end
end
-- Return (lowercase) filetype flag
function statusline.filetype()
local filetype = vim.bo.filetype
if filetype ~= '' then
return ',' .. filetype
else
return ''
end
end
local function statusline_focused()
local status = ''
local accent = "%3*"
if vim.bo.modified then
accent = "%4*"
end
status = accent .. " " .. modeflag() .. " %*%< "
status = status .. filename() .. "%="
status = status .. gitinfo()
--status = status .. zettelstatus() .. " "
status = status .. "[%M%R%{v:lua.dyamon.statusline.session()}%{v:lua.dyamon.statusline.fileenc()}%{v:lua.dyamon.statusline.filetype()}]" .. " "
status = status .. accent .. " %3l/%L %2c/%2{%len(getline('.'))%} [%P]"
--status = status .. " " .. lsp()
return status
end
local function statusline_blurred()
return " %<%f%="
end
function statusline.update()
local current = vim.g.statusline_winid == api.nvim_get_current_win()
if current then
return statusline_focused()
else
return statusline_blurred()
end
end
return statusline
|