aboutsummaryrefslogtreecommitdiff
path: root/lua
diff options
context:
space:
mode:
authormax397574 <[email protected]>2021-10-05 19:50:59 +0200
committermax397574 <[email protected]>2021-10-05 19:50:59 +0200
commit5a9b9b2e40249b40006a62d5597f8b9b6c720d49 (patch)
tree77a34839549505e4a57f23e2d824149d08108553 /lua
parentb41e139357fca7758c84e836e8acb9db4d204bc7 (diff)
feat: ✨more functions and refactoring
Diffstat (limited to 'lua')
-rw-r--r--lua/startuptools.lua47
1 files changed, 34 insertions, 13 deletions
diff --git a/lua/startuptools.lua b/lua/startuptools.lua
index fca84ee..fe88c51 100644
--- a/lua/startuptools.lua
+++ b/lua/startuptools.lua
@@ -1,9 +1,10 @@
local M = {}
-local nb = vim.api.nvim_create_namespace('noiceboard')
+local ns = vim.api.nvim_create_namespace('startuptools')
local opts = { noremap = true, silent = true }
local settings = {
+ -- every line should be same width without escaped \
header = {
" /$$ ",
" |__/ ",
@@ -14,16 +15,24 @@ local settings = {
"| $$ | $$| $$$$$$$| $$$$$$/ \\ $/ | $$| $$ | $$ | $$",
"|__/ |__/ \\_______/ \\______/ \\_/ |__/|__/ |__/ |__/",
},
+ -- name which will be displayed and command
tools = {
- ["Find File"] = "Telescope find_files",
- ["Find Word"] = "Telescope live_grep",
- ["Recent Files"] = "Telescope oldfiles",
- ["File Browser"] = "Telescope file_browser",
+ [" Find File"] = "Telescope find_files",
+ [" Find Word"] = "Telescope live_grep",
+ [" Recent Files"] = "Telescope oldfiles",
+ [" File Browser"] = "Telescope file_browser",
+ [" Config Files"] = 'lua require("telescope.builtin").find_files({cwd="~/.config"})',
+ [" Colorschemes"] = "Telescope colorscheme",
+ [" New File"] = "lua require'startuptools'.new_file()",
},
mappings = {
}
}
+function M.new_file()
+ local name = vim.fn.input("Filename: > ")
+ vim.cmd("e "..name)
+end
function M.check_line()
local line = vim.api.nvim_get_current_line()
@@ -49,7 +58,7 @@ local function set_lines(len, text, hi, pass)
vim.api.nvim_win_set_cursor(0, {count, 0})
if pass then vim.g.section_length = count end
for i=count,count+len do
- vim.api.nvim_buf_add_highlight(0, nb, hi, i, 1, -1)
+ vim.api.nvim_buf_add_highlight(0, ns, hi, i, 1, -1)
end
count = count + len
end
@@ -58,26 +67,38 @@ local function empty()
set_lines(1, {" "}, "TSString")
end
+local function set_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, 'swapfile', false)
+ vim.cmd[[set nonumber
+ set norelativenumber
+ ]]
+end
+
function M.display()
vim.api.nvim_buf_set_keymap(0, "n", "<CR>", ":lua require'startuptools'.check_line()<CR>", opts)
+ vim.api.nvim_buf_set_keymap(0, "n", "j", "2j", opts)
+ vim.api.nvim_buf_set_keymap(0, "n", "k", "2k", opts)
+ -- vim.api.nvim_buf_set_keymap(0, "n", "h", "<NOP>", opts)
+ -- vim.api.nvim_buf_set_keymap(0, "n", "l", "<NOP>", opts)
empty()
set_lines(#settings.header, settings.header, 'TSString')
local toolnames = {}
for name, _ in pairs(settings.tools) do
+ table.insert(toolnames, " ")
table.insert(toolnames, name)
end
empty()
set_lines(#toolnames, toolnames, 'TSString')
vim.cmd[[silent! %s/\s\+$//]] -- clear trailing whitespace
- 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, 'swapfile', false)
- vim.cmd[[set nonumber
- set norelativenumber
- ]]
+ set_options()
+ vim.api.nvim_win_set_cursor(0,{#settings.header + 5,vim.o.columns/2})
end
-function M.setup()
+function M.setup(update)
+ settings = vim.tbl_deep_extend("force", settings, update or {})
+
vim.cmd[[
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * lua if vim.fn.argc() == 0 and vim.fn.exists('std_in') then require"startuptools".display() end