-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbars.lua
More file actions
218 lines (179 loc) · 5.34 KB
/
Copy pathbars.lua
File metadata and controls
218 lines (179 loc) · 5.34 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
local augroup = vim.api.nvim_create_augroup("bars.nvim", {});
---@class vim.var_accessor
---@field bars_update_cache function
-- Updates default *bars & lines* value.
-- > From: `bars.nvim`
vim.g.bars_update_cache = function()
---|fS
if not vim.g.bars_cached then vim.g.bars_cached = {}; end
vim.g.bars_cached.statusline = vim.api.nvim_get_option_value("statusline", { scope = "global" });
vim.g.bars_cached.statuscolumn = vim.api.nvim_get_option_value("statuscolumn", { scope = "global" });
vim.g.bars_cached.winbar = vim.api.nvim_get_option_value("winbar", { scope = "global" });
vim.g.bars_cached.tabline = vim.api.nvim_get_option_value("tabline", { scope = "global" });
---|fE
end
vim.api.nvim_create_autocmd("VimEnter", {
group = augroup,
callback = function ()
vim.g.bars_update_cache();
require("bars.global");
require("bars.highlights").setup();
require("bars.statusline"):start();
require("bars.statuscolumn"):start();
require("bars.winbar"):start();
require("bars.tabline"):start();
end
});
vim.api.nvim_create_autocmd("WinNew", {
group = augroup,
callback = function ()
vim.schedule(function ()
local new_win = vim.api.nvim_get_current_win();
require("bars.statusline"):handle_new_window(new_win);
require("bars.statuscolumn"):handle_new_window(new_win);
require("bars.winbar"):handle_new_window(new_win);
require("bars.tabline"):handle_new_window(new_win);
end)
end
});
vim.api.nvim_create_autocmd({ "TabNew" }, {
callback = function ()
local max = vim.g.bars_tabline_visible_tabs or 5;
local tabs = #vim.api.nvim_list_tabpages();
if not package.loaded["bars.tabline"] then
return;
elseif vim.g.__bars_tabpage_list_locked == true then
--- List movement locked.
return;
elseif tabs <= max then
return;
end
vim.g.bars_tablist_start = math.max(1, (tabs + 1) - max);
end
});
vim.api.nvim_create_autocmd("OptionSet", {
group = augroup,
callback = function (event)
local style_change = { "statusline", "statuscolumn", "tabline", "winbar" };
local state_change = { "filetype", "buftype" };
vim.schedule(function ()
local event_win = vim.api.nvim_get_current_win();
if vim.list_contains(style_change, event.match) then
require("bars.statusline"):update_style(event_win);
require("bars.statuscolumn"):update_style(event_win);
require("bars.winbar"):update_style(event_win);
require("bars.tabline"):update_style(event_win);
elseif vim.list_contains(state_change, event.match) then
require("bars.statusline"):handle_new_window(event_win);
require("bars.statuscolumn"):handle_new_window(event_win);
require("bars.winbar"):handle_new_window(event_win);
require("bars.tabline"):handle_new_window(event_win);
end
end)
end
});
vim.api.nvim_create_autocmd("ColorScheme", {
group = augroup,
callback = function ()
require("bars.highlights").setup();
end
});
vim.api.nvim_create_autocmd("ModeChanged", {
group = augroup,
callback = function ()
pcall(vim.api.nvim__redraw, {
flush = true,
statuscolumn = true,
winbar = true,
tabline = true,
});
end
});
local commands = {
"Disable",
"Enable",
"Start",
"Stop",
"Toggle",
"disable",
"enable",
"toggle",
"update",
};
vim.api.nvim_create_user_command("Bars", function (data)
local command = data.fargs[1] and data.fargs[1] or "Toggle";
if not vim.list_contains(commands, command) then
vim.print("Not a sub-command: " .. command)
return;
end
local target = data.fargs[2] and { data.fargs[2] } or nil;
if target and target[1] == "?" then
vim.ui.input({
prompt = "Run command on target(s)?",
default = "",
}, function (v)
if not v then
return;
end
target = vim.split(v, " ", { trimempty = true });
if #target == 0 then target = nil; end
end);
end
local args = {};
for a, arg in ipairs(data.fargs or {}) do
if a > 2 then
if pcall(tonumber, arg) then
table.insert(args, tonumber(arg));
else
table.insert(args, arg);
end
end
end
if #args == 0 and not vim.list_contains({ "update" }, command) then
args = { vim.api.nvim_get_current_win() };
end
require("bars").exec(command, target, unpack(args));
end, {
desc = "Command for `bars.nvim`",
nargs = "*",
complete = function (leader, cmdline, cursor_pos)
local function create_completes (list)
local sorted = {};
for _, item in ipairs(list or {}) do
if leader == "" or string.match(tostring(item), "^".. leader) then
table.insert(sorted, tostring(item));
end
end
return sorted;
end
local before_cursor = string.sub(cmdline, 0, cursor_pos);
local tokens = vim.split(before_cursor, " ", { trimempty = true });
table.remove(tokens, 1);
local current_command = tokens[1] or "";
local targets = {
"?",
"all",
"statuscolumn",
"statusline",
"tabline",
"winbar",
};
if string.match(before_cursor, "%s$") then
if #tokens == 0 then
return create_completes(commands);
elseif #tokens == 1 then
return create_completes(targets);
elseif #tokens == 2 and not string.match(current_command, "^[A-Z]") then
return create_completes(vim.api.nvim_list_wins());
end
else
if #tokens == 1 then
return create_completes(commands);
elseif #tokens == 2 then
return create_completes(targets);
elseif #tokens == 3 and not string.match(current_command, "^[A-Z]") then
return create_completes(vim.api.nvim_list_wins());
end
end
end,
});