From 47346a37cf885c1cbb6d2f98fa32ad89b048af47 Mon Sep 17 00:00:00 2001 From: max397574 Date: Tue, 5 Oct 2021 15:56:09 +0200 Subject: =?UTF-8?q?feat(plugin):=20=E2=9C=A8automatically=20and=20function?= =?UTF-8?q?ality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/startuptools.lua | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/lua/startuptools.lua b/lua/startuptools.lua index 0d95c01..fca84ee 100644 --- a/lua/startuptools.lua +++ b/lua/startuptools.lua @@ -1,6 +1,8 @@ local M = {} local nb = vim.api.nvim_create_namespace('noiceboard') +local opts = { noremap = true, silent = true } + local settings = { header = { " /$$ ", @@ -11,10 +13,27 @@ local settings = { "| $$ | $$| $$_____/| $$ | $$ \\ $$$/ | $$| $$ | $$ | $$", "| $$ | $$| $$$$$$$| $$$$$$/ \\ $/ | $$| $$ | $$ | $$", "|__/ |__/ \\_______/ \\______/ \\_/ |__/|__/ |__/ |__/", + }, + tools = { + ["Find File"] = "Telescope find_files", + ["Find Word"] = "Telescope live_grep", + ["Recent Files"] = "Telescope oldfiles", + ["File Browser"] = "Telescope file_browser", + }, + mappings = { } } +function M.check_line() + local line = vim.api.nvim_get_current_line() + for name, command in pairs(settings.tools) do + if line:match(name) then + vim.cmd(command) + end + end +end + local function center(dict) local centered = {} local space_left = vim.o.columns - string.len(dict[1]) @@ -35,8 +54,34 @@ local function set_lines(len, text, hi, pass) count = count + len end -function M.set_header() +local function empty() + set_lines(1, {" "}, "TSString") +end + +function M.display() + vim.api.nvim_buf_set_keymap(0, "n", "", ":lua require'startuptools'.check_line()", opts) + empty() set_lines(#settings.header, settings.header, 'TSString') + local toolnames = {} + for name, _ in pairs(settings.tools) do + 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 + ]] +end + +function M.setup() + 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 + ]] end return M -- cgit v1.2.3