aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormax397574 <[email protected]>2021-10-07 16:30:32 +0200
committermax397574 <[email protected]>2021-10-07 16:30:32 +0200
commita1191a3019f5195d02170a5f1f0b67fccee60e92 (patch)
tree532afd30ac0e60114eaccb9dbfc200db64d6d963
parent0531a7b686725089c6457d80808ab5bc195ff295 (diff)
feat(plugin): ✨more buildingblocks and some improvements
-rw-r--r--lua/startup.lua121
-rw-r--r--lua/startup/buildingblocks/functions.lua27
-rw-r--r--lua/startup/buildingblocks/headers.lua85
-rw-r--r--lua/startup/themes/default.lua12
-rw-r--r--lua/startup/utils.lua1
-rw-r--r--settings_skeleton.lua6
6 files changed, 189 insertions, 63 deletions
diff --git a/lua/startup.lua b/lua/startup.lua
index 7c167b9..94779b0 100644
--- a/lua/startup.lua
+++ b/lua/startup.lua
@@ -17,6 +17,13 @@ local function create_mappings(mappings)
":lua require'startup'.check_line()<CR>",
opts
)
+ vim.api.nvim_buf_set_keymap(
+ 0,
+ "n",
+ "o",
+ "<cmd>lua require('startup').open_file()<CR>",
+ opts
+ )
for _, cmd in pairs(mappings) do
vim.api.nvim_buf_set_keymap(
0,
@@ -46,12 +53,19 @@ function M.check_line()
end
end
+function M.open_file()
+ local line = vim.api.nvim_get_current_line()
+ local filename = line:gsub "(\\/.-)+"
+ print(filename)
+ vim.cmd("e " .. filename)
+end
+
local function align(dict, alignment)
- local padding_calculated = 0
- if settings[current_section].padding < 1 then
- padding_calculated = vim.o.columns * settings[current_section].padding
+ local margin_calculated = 0
+ if settings[current_section].margin < 1 then
+ margin_calculated = vim.o.columns * settings[current_section].margin
else
- padding_calculated = settings[current_section].padding
+ margin_calculated = settings[current_section].margin
end
local aligned = {}
local max_len = utils.longest_line(dict)
@@ -62,17 +76,17 @@ local function align(dict, alignment)
end
elseif alignment == "left" then
for _, line in ipairs(dict) do
- table.insert(aligned, spaces(padding_calculated) .. line)
+ table.insert(aligned, spaces(margin_calculated) .. line)
end
elseif alignment == "right" then
for _, line in ipairs(dict) do
table.insert(
aligned,
- spaces(vim.o.columns - max_len - padding_calculated - 10) .. line
+ spaces(vim.o.columns - max_len - margin_calculated - 10) .. line
)
end
end
- padding_calculated = 0
+ margin_calculated = 0
return aligned
end
@@ -119,52 +133,55 @@ end
-- TODO: put inside schedule()
function M.display()
- local parts = { "header", "body", "footer" }
- for _, part in ipairs(parts) do
- current_section = part
- local options = settings[part]
- if options.highlight == "" then
- vim.cmd(
- "highlight Startup"
- .. part
- .. " guifg="
- .. options.default_color
- .. " guibg="
- .. settings.colors.background
- )
- options.highlight = "Startup" .. part
- end
- if options.type == "text" then
- set_lines(
- #options.content,
- options.content,
- options.align,
- options.highlight
- )
- elseif options.type == "mapping" then
- table.insert(sections_with_mappings, part)
- create_mappings(options.content)
- set_lines(
- #mapping_names(options.content),
- mapping_names(options.content),
- options.align,
- options.highlight
- )
- end
- if part == "header" then
- empty(settings.options.gap1)
- elseif part == "body" then
- empty(settings.options.gap2 + 1)
+ vim.schedule(function()
+ U.set_buf_options()
+ local parts = { "header", "body", "footer" }
+ for _, part in ipairs(parts) do
+ current_section = part
+ local options = settings[part]
+ if options.highlight == "" then
+ vim.cmd(
+ "highlight Startup"
+ .. part
+ .. " guifg="
+ .. options.default_color
+ .. " guibg="
+ .. settings.colors.background
+ )
+ options.highlight = "Startup" .. part
+ end
+ if options.type == "text" then
+ set_lines(
+ #options.content,
+ options.content,
+ options.align,
+ options.highlight
+ )
+ elseif options.type == "mapping" then
+ table.insert(sections_with_mappings, part)
+ create_mappings(options.content)
+ set_lines(
+ #mapping_names(options.content),
+ mapping_names(options.content),
+ options.align,
+ options.highlight
+ )
+ end
+ if part == "header" then
+ empty(settings.options.padding.header_body)
+ elseif part == "body" then
+ empty(settings.options.padding.body_footer + 1)
+ end
+ vim.cmd(options.command)
end
- vim.cmd(options.command)
- end
- current_section = ""
- vim.cmd [[silent! %s/\s\+$//]] -- clear trailing whitespace
- U.set_buf_options()
- vim.api.nvim_win_set_cursor(0, {
- #settings.header.content + settings.options.gap1 + 3,
- math.floor(vim.o.columns / 2),
- })
+ current_section = ""
+ vim.cmd [[silent! %s/\s\+$//]] -- clear trailing whitespace
+ vim.api.nvim_win_set_cursor(0, {
+ #settings.header.content + settings.options.padding.header_body + 3,
+ math.floor(vim.o.columns / 2),
+ })
+ vim.api.nvim_buf_set_option(0, "modifiable", false)
+ end)
end
function M.setup(update)
diff --git a/lua/startup/buildingblocks/functions.lua b/lua/startup/buildingblocks/functions.lua
index 7e103d3..9b4ca2d 100644
--- a/lua/startup/buildingblocks/functions.lua
+++ b/lua/startup/buildingblocks/functions.lua
@@ -21,7 +21,11 @@ local quotes = {
"",
"- Alan Perlis",
},
- { "Simplicity does not precede complexity, but follows it.", "", "- Alan Perlis" },
+ {
+ "Simplicity does not precede complexity, but follows it.",
+ "",
+ "- Alan Perlis",
+ },
{ "Optimization hinders evolution.", "", "- Alan Perlis" },
{
"Recursion is the root of computation since it trades description for time.",
@@ -333,7 +337,11 @@ local quotes = {
"",
"Don't get so engrossed in the details that you forget to check what's happening around you.",
},
- { "Invest regularly in your knowledge portfolio.", "", "Make learning a habit." },
+ {
+ "Invest regularly in your knowledge portfolio.",
+ "",
+ "Make learning a habit.",
+ },
{
"It's both what you say and the way you say it.",
"",
@@ -678,4 +686,19 @@ function M.quote()
local index = math.random() * #quotes
return quotes[math.floor(index) + 1]
end
+
+function M.oldfiles(amount)
+ local oldfiles = {}
+ table.insert(oldfiles, "Press 'o' to open the file under the cursor")
+ local count = 0
+ for _, file in ipairs(vim.v.oldfiles) do
+ if count == amount then
+ break
+ end
+ table.insert(oldfiles, file)
+ count = count + 1
+ end
+ return oldfiles
+end
+
return M
diff --git a/lua/startup/buildingblocks/headers.lua b/lua/startup/buildingblocks/headers.lua
index 4df1798..344f89a 100644
--- a/lua/startup/buildingblocks/headers.lua
+++ b/lua/startup/buildingblocks/headers.lua
@@ -53,4 +53,89 @@ function M.neovim_logo()
}
end
+function M.pacman()
+ return {
+ "================================================.",
+ " .-. .-. .--. |",
+ " | OO| | OO| / _.-' .-. .-. .-. .''. |",
+ " | | | | \\ '-. '-' '-' '-' '..' |",
+ " '^^^' '^^^' '--' |",
+ "===============. .-. .================. .-. |",
+ " | | | | | '-' |",
+ " | | | | | |",
+ " | ':-:' | | .-. |",
+ "42 | '-' | | '-' |",
+ "===============' '================' |",
+ }
+end
+
+function M.zelda_logo_big()
+ return {
+ " _ ",
+ " /_\\ ",
+ "_ )_( _ ",
+ "|`-.___,.-~'`|=|`'~-.,___,-'| ",
+ "| __________|=|__________ | ",
+ "| | ______|=|__________| | ___ _ _ _ _ _ ",
+ "| | | ____|=|_____ / | | |_| |_ | |_ | _ |_ |\\| |\\ /\\ |_ ",
+ "| | | / |=| / /| | | | | |_ |_ |_ |_| |_ | | |/ \\/ | ",
+ "| | |/ ,-|_|-. / / /_|_|______ ______ _______ ____ ",
+ "| | ,' _____ / // / \\ ___ |\\ / \\ `. \\ \\ ",
+ "| | / ,'| A |/ // / | | \\ | | | | |`. \\ / \\ ",
+ "| | /_// |/V\\/ // / | | \\| | | | | \\ \\ / /\\ \\ ",
+ "| | /__| |/ / / | | | | | | \\ | / / \\ \\ ",
+ "| | /\\ | / /| /\\ | |__/| | | | | | || | | | ",
+ "| | / \\ |/ // // \\ | __ | | | | | | || |____| | ",
+ "| | / \\/ |/ // \\ | | \\| | | | | | || ____ | ",
+ "| | / / // \\ | | | | | | / || | | | ",
+ "| | / / / /| \\ | | /| | | /| | | / / | | | | ",
+ "| |/_____/ // / |________\\| |___/ | | |___/ | | |,' / | | | | ",
+ "| | / // /| | /_________|/_________|/______,' /____\\ /____\\ ",
+ "\\ \\ / // / | | /|/ /_ ___ ___ _ _ _ _ ___ ",
+ " \\ \\ / / /| | |______/ | //_\\ | | |\\| |/ |/\\ | |_||_ |_)/_\\(_` | ",
+ " \\ \\/______| | |________|/ | | |_ | | | |\\ |\\/ | | ||_ | | |._) | ",
+ " `.`. | | | ,',' ",
+ " `.`. | | | ,',' _ _ _ _ ",
+ " `.`-.| | |,-',' |.\\ |.\\ |.\\ |.\\ ",
+ " `-.| | |,-' \\\\\\ \\\\\\ \\\\\\ \\\\\\ ",
+ " | | | ________\\\\\\______\\\\\\______\\\\\\______\\\\\\_____________ ",
+ " | | | | .-- __ __ ,--. __ __ __| _ |",
+ " | | | | |- / \\ | | | ` `--. | | | / \\ | ` / |(_` |",
+ " | | | | | \\__/ \\_/| | .__/ \\/ \\/ \\__/ | \\__|._) |",
+ " | | | '---------------------------------------------------'",
+ " \\|/ \\\\\\ /| \\\\\\ /| \\\\\\ /| \\\\\\ /| ",
+ " V __\\\\V / __\\\\V / __\\\\V / __\\\\V / ",
+ " \\___O/ \\___O/ \\___O/ \\___O/ ",
+ " \\/\\ \\/\\ \\/\\ \\/\\ ",
+ " \\/\\ \\/\\ \\/\\ \\/\\ ",
+ " (O) (O) (O) (O) ",
+ }
+end
+
+function M.doom_nvim()
+ return {
+ " ",
+ "================= =============== =============== ======== ========",
+ "\\\\ . . . . . . .\\\\ //. . . . . . .\\\\ //. . . . . . .\\\\ \\\\. . .\\\\// . . //",
+ "||. . ._____. . .|| ||. . ._____. . .|| ||. . ._____. . .|| || . . .\\/ . . .||",
+ "|| . .|| ||. . || || . .|| ||. . || || . .|| ||. . || ||. . . . . . . ||",
+ "||. . || || . .|| ||. . || || . .|| ||. . || || . .|| || . | . . . . .||",
+ "|| . .|| ||. _-|| ||-_ .|| ||. . || || . .|| ||. _-|| ||-_.|\\ . . . . ||",
+ "||. . || ||-' || || `-|| || . .|| ||. . || ||-' || || `|\\_ . .|. .||",
+ "|| . _|| || || || || ||_ . || || . _|| || || || |\\ `-_/| . ||",
+ "||_-' || .|/ || || \\|. || `-_|| ||_-' || .|/ || || | \\ / |-_.||",
+ "|| ||_-' || || `-_|| || || ||_-' || || | \\ / | `||",
+ "|| `' || || `' || || `' || || | \\ / | ||",
+ "|| .===' `===. .==='.`===. .===' /==. | \\/ | ||",
+ "|| .==' \\_|-_ `===. .===' _|_ `===. .===' _-|/ `== \\/ | ||",
+ "|| .==' _-' `-_ `=' _-' `-_ `=' _-' `-_ /| \\/ | ||",
+ "|| .==' _-' `-__\\._-' `-_./__-' `' |. /| | ||",
+ "||.==' _-' `' | /==.||",
+ "==' _-' N E O V I M \\/ `==",
+ "\\ _-' `-_ /",
+ " `'' ``' ",
+ " ",
+ }
+end
+
return M
diff --git a/lua/startup/themes/default.lua b/lua/startup/themes/default.lua
index 3c7fc07..62d1848 100644
--- a/lua/startup/themes/default.lua
+++ b/lua/startup/themes/default.lua
@@ -3,7 +3,7 @@ local settings = {
header = {
type = "text",
align = "center",
- padding = 5,
+ margin = 5,
content = {
" /$$ ",
" |__/ ",
@@ -22,7 +22,7 @@ local settings = {
body = {
type = "mapping",
align = "center",
- padding = 5,
+ margin = 5,
content = {
[" Find File"] = { "Telescope find_files", "<leader>ff" },
[" Find Word"] = { "Telescope live_grep", "<leader>lg" },
@@ -38,7 +38,7 @@ local settings = {
footer = {
type = "text",
align = "center",
- padding = 5,
+ margin = 5,
content = { "startup.nvim" },
highlight = "TSString",
default_color = "#FFFFFF",
@@ -48,8 +48,10 @@ local settings = {
options = {
mapping_keys = true,
empty_lines_between_mappings = true,
- gap1 = 3,
- gap2 = 4,
+ padding = {
+ header_body = 3,
+ body_footer = 4,
+ },
},
colors = {
background = "#1f2227",
diff --git a/lua/startup/utils.lua b/lua/startup/utils.lua
index f407a15..b4c80eb 100644
--- a/lua/startup/utils.lua
+++ b/lua/startup/utils.lua
@@ -57,7 +57,6 @@ function U.set_buf_options()
vim.api.nvim_buf_set_option(0, "bufhidden", "wipe")
vim.api.nvim_buf_set_option(0, "buftype", "nofile")
vim.api.nvim_buf_set_option(0, "filetype", "dashboard")
- vim.api.nvim_buf_set_option(0, "modifiable", false)
vim.api.nvim_buf_set_option(0, "swapfile", false)
vim.cmd [[setlocal nonu nornu]]
end
diff --git a/settings_skeleton.lua b/settings_skeleton.lua
index 7e1c9b5..6204a6c 100644
--- a/settings_skeleton.lua
+++ b/settings_skeleton.lua
@@ -26,9 +26,9 @@ local example_section = {
command = "echo 'test worked'", -- a command which will be exected when section gets loaded
}
local settings = {
- header = {},
- body = {},
- footer = {},
+ -- header = {<see example section>},
+ -- body = {<see example section>},
+ -- footer = {<see example section>},
options = {
mapping_keys = true, -- display keys for mappings (e.g. <leader>ff)
empty_lines_between_mappings = true, -- empty lines between mapping names