-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalpha.lua
138 lines (126 loc) ยท 3.58 KB
/
alpha.lua
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
return {
"goolord/alpha-nvim",
event = "VimEnter",
config = function()
local alpha = require("alpha")
local dashboard = require("alpha.themes.dashboard")
local utils = require("utils")
_Gopts = {
position = "center",
hl = "Type",
wrap = "overflow",
}
local function get_all_files_in_dir(dir)
local files = {}
local scan = vim.fn.globpath(dir, "**/*.lua", true, true)
for _, file in ipairs(scan) do
table.insert(files, file)
end
return files
end
local function load_random_header()
math.randomseed(os.time())
local header_folder = vim.fn.stdpath("config") .. "/lua/custom/plugins/header_img/"
local files = get_all_files_in_dir(header_folder)
if #files == 0 then
return nil
end
local random_file = files[math.random(#files)]
local relative_path = random_file:sub(#header_folder + 1)
local module_name = "custom.plugins.header_img."
.. relative_path:gsub("/", "."):gsub("\\", "."):gsub("%.lua$", "")
package.loaded[module_name] = nil
local ok, module = pcall(require, module_name)
if ok and module.header then
return module.header
else
return nil
end
end
local function change_header()
local new_header = load_random_header()
if new_header then
dashboard.config.layout[2] = new_header
vim.cmd("AlphaRedraw")
else
print("No images inside header_img folder.")
end
end
local header = load_random_header()
if header then
dashboard.config.layout[2] = header
else
print("No images inside header_img folder.")
end
dashboard.section.tasks = {
type = "text",
val = utils.get_today_tasks(),
opts = {
position = "center",
hl = "Comment",
width = 50,
},
}
dashboard.section.buttons.val = {
dashboard.button("<C-d>", "๐ Open daily-notes", ":ObsidianToday<CR>"),
dashboard.button("<C-r>", "โ Open random note", ":lua require('utils').open_random_note()<CR>"),
dashboard.button("<C-t>", "โ
Toggle tasks", function()
require("utils").show_interactive_tasks()
end),
dashboard.button("w", "๐๏ธ Change header image", function()
change_header()
end),
dashboard.button("c", "๐ ๏ธ Settings", ":e $HOME/.config/nvim/init.lua<CR>"),
dashboard.button("r", "โ Recent files", ":Telescope oldfiles <CR>"),
dashboard.button("t", "๐ฎ Practice typing with Typr ", ":Typr<CR>"),
dashboard.button("u", "๐ Update plugins", "<cmd>Lazy update<CR>"),
}
dashboard.config.layout = {
{ type = "padding", val = 3 },
header,
{ type = "padding", val = 2 },
{
type = "group",
val = {
{
type = "group",
val = {
{
type = "text",
val = "๐
Tasks for today",
opts = { hl = "Keyword", position = "center" },
},
dashboard.section.tasks,
},
opts = { spacing = 1 },
},
{
type = "group",
val = dashboard.section.buttons.val,
opts = { spacing = 1 },
},
},
opts = {
layout = "horizontal",
},
},
{ type = "padding", val = 2 },
dashboard.section.footer,
}
vim.api.nvim_create_autocmd("User", {
pattern = "LazyVimStarted",
desc = "Add Alpha dashboard footer",
once = true,
callback = function()
local stats = require("lazy").stats()
local ms = math.floor(stats.startuptime * 100 + 0.5) / 100
dashboard.section.footer.val =
{ " ", " ", " ", "๏ง Loaded " .. stats.count .. " plugins ๏ฆ in " .. ms .. " ms " }
dashboard.section.header.opts.hl = "DashboardFooter"
pcall(vim.cmd.AlphaRedraw)
end,
})
dashboard.opts.opts.noautocmd = true
alpha.setup(dashboard.opts)
end,
}