-
Notifications
You must be signed in to change notification settings - Fork 0
/
alpha.lua
303 lines (269 loc) · 13.3 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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
-- Alpha (dashboard) for neovim
local options
-- Only runs this script if Alpha Screen loads -- only if there isn't files to read
if (vim.api.nvim_exec('echo argc()', true) == "0")
then
--math.randomseed( os.time() ) -- For random header.
-- To split our quote, artist and source.
-- And automatically center it for screen loader of the header.
local function split(s)
local t = {}
local max_line_length = vim.api.nvim_get_option('columns')
local longest = 0 -- Value of longest string is 0 by default
for far in s:gmatch("[^\r\n]+") do
-- Break the line if it's actually bigger than terminal columns
local line
far:gsub('(%s*)(%S+)',
function(spc, word)
if not line or #line + #spc + #word > max_line_length then
table.insert(t, line)
line = word
else
line = line..spc..word
longest = max_line_length
end
end)
-- Get the string that is the longest
if (#line > longest) then
longest = #line
end
table.insert(t, line)
end
-- Center all strings by the longest
for i = 1, #t do
local space = longest - #t[i]
local left = math.floor(space/2)
local right = space - left
t[i] = string.rep(' ', left) .. t[i] .. string.rep(' ', right)
end
return t
end
-- Function to retrieve console output.
local function capture(cmd)
local handle = assert(io.popen(cmd, 'r'))
local output = assert(handle:read('*a'))
handle:close()
return output
end
-- Create button for initial keybind.
--- @param sc string
--- @param txt string
--- @param hl string
--- @param keybind string optional
--- @param keybind_opts table optional
local function button(sc, txt, hl, keybind, keybind_opts)
local sc_ = sc:gsub("%s", ""):gsub("SPC", "<leader>")
local opts = {
position = "center",
shortcut = sc,
cursor = 5,
width = 50,
align_shortcut = "right",
hl_shortcut = hl,
}
if keybind then
keybind_opts = vim.F.if_nil(keybind_opts, {noremap = true, silent = true, nowait = true})
opts.keymap = {"n", sc_, keybind, keybind_opts}
end
local function on_press()
local key = vim.api.nvim_replace_termcodes(sc_ .. '<Ignore>', true, false, true)
vim.api.nvim_feedkeys(key, "normal", false)
end
return {
type = "button",
val = txt,
on_press = on_press,
opts = opts,
}
end
-- All custom headers
Headers = {
{
[[ .-'''''-. ]],
[[ .' `. ]],
[[ : : ]],
[[ : :]],
[[ : _/| :]],
[[ : =/_/ : ]],
[[ `._/ | .' ]],
[[ ( / ,|...-' ]],
[[ \_/^\/||__ ]],
[[ _/~ `""~`"` \_ ]],
[[ __/ -'. ` . `\_\__ ]],
[[/jgs \ \-.\ ]],
}, -- jgs
--{
-- [[ ]],
-- [[ ███████████ █████ ██ ]],
-- [[ ███████████ █████ ]],
-- [[ ████████████████ ███████████ ███ ███████ ]],
-- [[ ████████████████ ████████████ █████ ██████████████ ]],
-- [[ █████████████████████████████ █████ █████ ████ █████ ]],
-- [[ ██████████████████████████████████ █████ █████ ████ █████ ]],
-- [[ ██████ ███ █████████████████ ████ █████ █████ ████ ██████ ]],
-- [[ ██████ ██ ███████████████ ██ █████████████████ ]],
-- [[ ██████ ██ ███████████████ ██ █████████████████ ]],
--},
-- {
-- '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ',
-- '⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ ',
-- '⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀ ',
-- '⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀ ',
-- '⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀ ',
-- '⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀ ',
-- '⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀ ',
-- '⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀ ',
-- '⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀ ',
-- '⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀ ',
-- '⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀ ',
-- '⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀ ',
-- '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ',
-- '⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀ ',
-- '⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀⠀⠀⠀ ',
-- },
-- {
-- [[================= =============== =============== ======== ========]],
-- [[\\ . . . . . . .\\ //. . . . . . .\\ //. . . . . . .\\ \\. . .\\// . . //]],
-- [[||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\/ . . .||]],
-- [[|| . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||]],
-- [[||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||]],
-- [[|| . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\ . . . . ||]],
-- [[||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\_ . .|. .||]],
-- [[|| . _|| || || || || ||_ . || || . _|| || || || |\ `-_/| . ||]],
-- [[||_-' || .|/ || || \|. || `-_|| ||_-' || .|/ || || | \ / |-_.||]],
-- [[|| ||_-' || || `-_|| || || ||_-' || || | \ / | `||]],
-- [[|| `' || || `' || || `' || || | \ / | ||]],
-- [[|| .===' `===. .==='.`===. .===' /==. | \/ | ||]],
-- [[|| .==' \_|-_ `===. .===' _|_ `===. .===' _-|/ `== \/ | ||]],
-- [[|| .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \/ | ||]],
-- [[|| .==' _-' '-__\._-' '-_./__-' `' |. /| | ||]],
-- [[||.==' _-' `' | /==.||]],
-- [[==' _-' N E O V I M \/ `==]],
-- [[\ _-' `-_ /]],
-- [[ `'' ``' ]],
-- },
-- {
-- [[ /|_ ]],
-- [[ (o o / ]],
-- [[ |. ~. ]],
-- [[ じしf_,)ノ ]],
-- },
-- {
-- ' ▀████▀▄▄ ▄█ ',
-- ' █▀ ▀▀▄▄▄▄▄ ▄▄▀▀█ ',
-- ' ▄ █ ▀▀▀▀▄ ▄▀ ',
-- ' ▄▀ ▀▄ ▀▄ ▀▄▀ ',
-- ' ▄▀ █ █▀ ▄█▀▄ ▄█ ',
-- ' ▀▄ ▀▄ █ ▀██▀ ██▄█ ',
-- ' ▀▄ ▄▀ █ ▄██▄ ▄ ▄ ▀▀ █ ',
-- ' █ ▄▀ █ ▀██▀ ▀▀ ▀▀ ▄▀ ',
-- ' █ █ █ ▄▄ ▄▀ ',
-- },
-- {
-- " ",
-- " ███╗ ██╗███████╗ ██████╗ ██╗ ██╗██╗███╗ ███╗ ",
-- " ████╗ ██║██╔════╝██╔═══██╗██║ ██║██║████╗ ████║ ",
-- " ██╔██╗ ██║█████╗ ██║ ██║██║ ██║██║██╔████╔██║ ",
-- " ██║╚██╗██║██╔══╝ ██║ ██║╚██╗ ██╔╝██║██║╚██╔╝██║ ",
-- " ██║ ╚████║███████╗╚██████╔╝ ╚████╔╝ ██║██║ ╚═╝ ██║ ",
-- " ╚═╝ ╚═══╝╚══════╝ ╚═════╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ ",
-- " ",
-- },
-- {
-- [[ __ ]],
-- [[ ___ ___ ___ __ __ /\_\ ___ ___ ]],
-- [[ / _ `\ / __`\ / __`\/\ \/\ \\/\ \ / __` __`\ ]],
-- [[/\ \/\ \/\ __//\ \_\ \ \ \_/ |\ \ \/\ \/\ \/\ \ ]],
-- [[\ \_\ \_\ \____\ \____/\ \___/ \ \_\ \_\ \_\ \_\]],
-- [[ \/_/\/_/\/____/\/___/ \/__/ \/_/\/_/\/_/\/_/]],
-- },
}
--
-- Sections for Alpha.
--
local header = {
type = "text",
-- val = Headers[math.random(#Headers)],
val = Headers[1],
opts = {
position = "center",
hl = "Whitespace"
-- wrap = "overflow";
}
}
local footer = {
type = "text",
-- Change 'rdn' to any program that gives you a random quote.
-- https://github.com/BeyondMagic/scripts/blob/master/quotes/rdn
-- Which returns one to three lines, being each divided by a line break.
-- Or just an array: { "I see you:", "Above you." }
val = {
"We accept the love we think we deserve.",
" Mr. Callahan",
"The Perks of Being a Wallflower",
}, -- split(capture('rdn')),
hl = "NvimTreeRootFolder",
opts = {
position = "center",
hl = "Whitespace",
}
}
local buttons = {
type = "group",
val = {
button("e", " New Buffer", 'RainbowRed', ':tabnew<CR>'),
button("f", " Find file", 'RainbowYellow', ':Telescope find_files<CR>'),
button("h", " Recently opened files", 'RainbowBlue', ':Telescope oldfiles<CR>'),
button("l", " Projects", 'RainbowOrange', ':Telescope marks<CR>'),
--button("r", " Frecency/MRU", 'RainbowCyan', ':Telescope oldfiles<CR>'),
button("g", " Open Last Session", 'RainbowGreen', ':source ~/.config/nvim/session.vim<CR>'),
--button("m", " Word Finder", 'RainbowViolet', ':Telescope live_grep<CR>'),
},
opts = {
spacing = 1,
}
}
--
-- Centering handler of ALPHA
--
local ol = { -- occupied lines
icon = #header.val, -- CONST: number of lines that your header will occupy
message = #footer.val, -- CONST: because of padding at the bottom
length_buttons = #buttons.val * 2 - 1, -- CONST: it calculate the number that buttons will occupy
neovim_lines = 2, -- CONST: 2 of command line, 1 of the top bar
padding_between = 3, -- STATIC: can be set to anything, padding between keybinds and header
}
local left_terminal_value = vim.api.nvim_get_option('lines') - (ol.length_buttons + ol.message + ol.padding_between + ol.icon + ol.neovim_lines)
-- Not screen enough to run the command.
if (left_terminal_value >= 0) then
local top_padding = math.floor(left_terminal_value / 2)
local bottom_padding = left_terminal_value - top_padding
--
-- Set alpha sections
--
options = {
layout = {
{ type = "padding", val = top_padding },
header,
{ type = "padding", val = ol.padding_between },
buttons,
footer,
{ type = "padding", val = bottom_padding },
},
opts = {
margin = 5
},
}
end
--else
--vim.api.nvim_exec('silent source ~/.config/nvim/session.vim', false)
end
return {
"goolord/alpha-nvim",
dependencies = 'kyazdani42/nvim-web-devicons',
config = function ()
if (options ~= nil) then
require'alpha'.setup(options)
end
end
}