From db2f9b522b74390e3cb7a1b299b08a708cc98391 Mon Sep 17 00:00:00 2001 From: max397574 Date: Tue, 5 Oct 2021 20:11:45 +0200 Subject: =?UTF-8?q?feat:=20=E2=9C=A8added=20mappings=20and=20refactor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/startuptools.lua | 53 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'lua/startuptools.lua') diff --git a/lua/startuptools.lua b/lua/startuptools.lua index 77efa7a..dfa456a 100644 --- a/lua/startuptools.lua +++ b/lua/startuptools.lua @@ -17,17 +17,33 @@ 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", - [" Config Files"] = 'lua require("telescope.builtin").find_files({cwd="~/.config"})', - [" Colorschemes"] = "Telescope colorscheme", - [" New File"] = "lua require'startuptools'.new_file()", + [" Find File"] = {"Telescope find_files", "ff"}, + [" Find Word"] = {"Telescope live_grep", "lg"}, + [" Recent Files"] = {"Telescope oldfiles", "of"}, + [" File Browser"] = {"Telescope file_browser", "fb"}, + [" Config Files"] = {'lua require("telescope.builtin").find_files({cwd="~/.config"})', "cf"}, + [" Colorschemes"] = {"Telescope colorscheme", "cs"}, + [" New File"] = {"lua require'startuptools'.new_file()", "nf"}, }, - mappings = {}, + options = { + align = "center", + mapping_names = true, + } } +local function create_mappings() + vim.api.nvim_buf_set_keymap( + 0, + "n", + "", + ":lua require'startuptools'.check_line()", + opts + ) + for _, cmd in pairs(settings.tools) do + vim.api.nvim_buf_set_keymap(0, "n", cmd[2], ""..cmd[1].."", opts) + end +end + function M.new_file() local name = vim.fn.input "Filename: > " vim.cmd("e " .. name) @@ -37,7 +53,7 @@ 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) + vim.cmd(command[1]) end end end @@ -78,23 +94,19 @@ local function set_options() end function M.display() - vim.api.nvim_buf_set_keymap( - 0, - "n", - "", - ":lua require'startuptools'.check_line()", - opts - ) + create_mappings() 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", "", opts) - -- vim.api.nvim_buf_set_keymap(0, "n", "l", "", opts) empty() set_lines(#settings.header, settings.header, "TSString") local toolnames = {} - for name, _ in pairs(settings.tools) do + for name, cmd in pairs(settings.tools) do table.insert(toolnames, " ") - table.insert(toolnames, name) + if settings.options.mapping_names then + table.insert(toolnames, name .. " " .. cmd[2]) + else + table.insert(toolnames, name) + end end empty() set_lines(#toolnames, toolnames, "TSString") @@ -105,7 +117,6 @@ end 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 -- cgit v1.2.3