-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_api.lua
More file actions
89 lines (71 loc) · 1.99 KB
/
user_api.lua
File metadata and controls
89 lines (71 loc) · 1.99 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
local uv = vim.uv or vim.loop
local timer = nil ---@type uv.uv_timer_t|nil
local timer_cb = vim.schedule_wrap(function()
local logfile = vim.fs.joinpath(vim.fn.stdpath('state'), 'nvim.log')
local stat = uv.fs_stat(logfile)
if not stat or stat.size < 1048576 then -- 1GiB
return
end
local fd = uv.fs_open(logfile, 'w', tonumber('644', 8))
if not fd then
return
end
local ok = uv.fs_ftruncate(fd, 0)
uv.fs_close(fd)
if ok then
vim.notify(('`%s` has been cleared!'):format(logfile), vim.log.levels.INFO)
end
end)
local function make_timer()
if timer and timer:is_active() then
return
end
timer = uv.new_timer()
if not timer then
return
end
timer:start(1000, 900000, timer_cb)
vim.api.nvim_create_autocmd({ 'VimLeavePre' }, {
group = vim.api.nvim_create_augroup('log_autoclear', { clear = true }),
callback = function()
if not (timer and timer:is_active()) then
return
end
timer:stop()
timer = nil
end,
})
end
---@class UserAPI
local M = {}
function M.disable_netrw()
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
end
---@param commands? table<string, User.Commands.CmdSpec>
---@param verbose? boolean
function M.setup(commands, verbose)
require('user_api.check').validate({
commands = { commands, { 'table', 'nil' }, true },
verbose = { verbose, { 'boolean', 'nil' }, true },
})
if verbose == nil then
verbose = false
end
require('user_api.commands').setup(commands or {})
require('user_api.update').setup()
require('user_api.opts').setup()
require('user_api.distro').setup(verbose)
require('user_api.config.neovide').setup()
require('user_api.pickers').setup()
local desc = require('user_api.maps').new_desc
require('user_api.config.keymaps').set({
n = {
['<leader>U'] = { group = '+User API' },
['<leader><leader>'] = { require('user_api.pickers').run, desc('Select Picker') },
},
})
make_timer()
end
return M
-- vim: set ts=2 sts=2 sw=2 et ai si sta: