-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.lua
144 lines (126 loc) · 3.99 KB
/
dashboard.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
139
140
141
142
143
144
return {
"goolord/alpha-nvim",
dependencies = {
"nvim-tree/nvim-web-devicons",
"nvim-lua/plenary.nvim",
{ "juansalvatore/git-dashboard-nvim", dependencies = { "nvim-lua/plenary.nvim" } },
},
config = function()
-- Import alpha and dashboard
local alpha = require("alpha")
local dashboard = require("alpha.themes.dashboard")
-- Define custom icons
local icons = {
ui = {
file = "",
files = "",
open_folder = "",
config = "",
git = "",
close = "",
},
}
local function whitespace_only(str)
return str:match("^%s*$") ~= nil
end
local function pad(n)
return { type = "padding", val = n }
end
local function center_header(header)
local lines = {}
for line in string.gmatch(header, "[^\n]+") do
table.insert(lines, line)
end
local width = vim.api.nvim_win_get_width(0) -- Get the width of the current window
local padding = math.floor((width - #lines[1]) / 2) -- Calculate padding based on the first line length
for i, line in ipairs(lines) do
lines[i] = string.rep(" ", padding) .. line
end
return lines
end
local function format_git_header()
local git_dashboard_raw = require("git-dashboard-nvim").setup({})
local git_dashboard = {}
for _, line in ipairs(git_dashboard_raw) do
if not whitespace_only(line) then
table.insert(git_dashboard, line)
end
end
local git_repo = git_dashboard[1]
local git_branch = git_dashboard[#git_dashboard]
if git_repo == nil and git_branch == nil then
return {
type = "text",
val = "",
opts = { position = "center" },
}, {}
end
local git_branch_section = {
type = "text",
val = " " .. git_repo .. ":" .. string.sub(git_branch, 5, #git_branch),
opts = { position = "center" },
}
return git_branch_section, { unpack(git_dashboard, 2, #git_dashboard - 1) }
end
-- Define custom header with ASCII art or any custom message
local ascii_header = [[
________ ___ ___ ________ _________ ________ ________
|\ ____\|\ \|\ \|\ ____\|\___ ___\\ __ \|\ _____\
\ \ \___|\ \ \\\ \ \ \___|\|___ \ \_\ \ \|\ \ \ \__/
\ \ \ __\ \ \\\ \ \_____ \ \ \ \ \ \ __ \ \ __\
\ \ \|\ \ \ \\\ \|____|\ \ \ \ \ \ \ \ \ \ \ \_|
\ \_______\ \_______\____\_\ \ \ \__\ \ \__\ \__\ \__\
\|_______|\|_______|\_________\ \|__| \|__|\|__|\|__|
\|_________|
]]
local git_branch_section, commit_history = format_git_header()
for _, line in ipairs(commit_history) do
ascii_header = ascii_header .. "\n" .. string.rep(" ", 3) .. line
end
local custom_header = center_header(ascii_header)
local header = { type = "text", val = custom_header }
local buttons = {
type = "group",
val = {
dashboard.button("e", icons.ui.file .. " New file", "<cmd>new<CR>"),
dashboard.button("o", icons.ui.files .. " Recent Files", "<cmd>Telescope oldfiles<cr>"),
dashboard.button("f", icons.ui.open_folder .. " Explorer", "<cmd>Oil<cr>"),
dashboard.button(
"c",
icons.ui.config .. " Neovim config",
"<cmd>Oil /home/cafebabe/install/dotfiles/config/nvim<cr>"
),
dashboard.button("g", icons.ui.git .. " Open Git", "<cmd>Neogit<CR>"),
dashboard.button("l", " Lazy", "<cmd>Lazy<cr>"),
dashboard.button("q", icons.ui.close .. " Quit NVIM", ":qa<CR>"),
},
}
-- Custom footer showing number of plugins loaded
local footer = {
type = "text",
val = { "⚡" .. require("lazy").stats().loaded .. " plugins loaded." },
opts = { position = "center", hl = "Comment" },
}
local bottom_section = {
type = "text",
val = "Hi Gustaf, It's " .. os.date(" %H:%M ") .. "How are you doing today?",
opts = { position = "center" },
}
-- Setting up the alpha layout
alpha.setup({
layout = {
pad(4),
header,
pad(1),
git_branch_section,
pad(2),
buttons,
pad(2),
bottom_section,
pad(2),
footer,
},
position = "center",
})
end,
}