Skip to content

Commit 3a73c19

Browse files
committed
add utils for snacks dashboard
1 parent dc58b58 commit 3a73c19

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
local headers = {
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+
--- Get a header from the list of headers
49+
---@param index number|nil Optional index to get specific header
50+
---@param random boolean|nil If true, return a random header
51+
---@return table Header lines
52+
local function get_header(index, random)
53+
if random then
54+
-- Return a random header if random is true
55+
math.randomseed(os.time()) -- Seed to get a different random each time
56+
return headers[math.random(1, #headers)]
57+
elseif index then
58+
-- Return the header at the specified index
59+
return headers[index]
60+
else
61+
-- Default to the first header if neither is specified
62+
return headers[1]
63+
end
64+
end
65+
66+
return get_header
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
-- lua/utils/greeting.lua
2+
3+
local M = {}
4+
5+
---@param str string
6+
---@return string
7+
local function capitalize(str)
8+
if str == nil or str == "" then
9+
return ""
10+
end
11+
return str:sub(1, 1):upper() .. str:sub(2)
12+
end
13+
14+
---@return { main: table, late: table|nil }
15+
function M.get_greeting()
16+
local hour = tonumber(os.date("%H"))
17+
local user = capitalize(os.getenv("USER") or "user")
18+
local hostname = capitalize(vim.fn.hostname())
19+
20+
local greeting
21+
local icon
22+
if hour >= 5 and hour < 12 then
23+
greeting = "Good morning"
24+
icon = "🌤️ "
25+
elseif hour >= 12 and hour < 18 then
26+
greeting = "Good afternoon"
27+
icon = "☀️ "
28+
else
29+
greeting = "Good evening"
30+
icon = ""
31+
end
32+
33+
local main = {
34+
{ icon, hl = "SnacksDashboardIcon" },
35+
{ greeting .. " ", hl = "SnacksDashboardDesc" },
36+
{ user, hl = "SnacksDashboardKey" },
37+
{ ", welcome to ", hl = "SnacksDashboardDesc" },
38+
{ hostname, hl = "SnacksDashboardKey" },
39+
{ "", hl = "SnacksDashboardIcon" },
40+
}
41+
42+
local late = nil
43+
if hour >= 20 or hour < 5 then
44+
late = {
45+
{ "󰤄 It's getting late, consider catching some sleep! 󰒲 ", hl = "DiagnosticWarn" },
46+
}
47+
end
48+
49+
return { main = main, late = late }
50+
end
51+
52+
return M

0 commit comments

Comments
 (0)