From b6807d63cd284a73969f81da7c4b5213880c8bc5 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sun, 22 Oct 2023 18:08:38 -0400 Subject: move config menu --- init.lua | 2 +- lua/cfgmenu.lua | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lua/mngr/init.lua | 1 - lua/mngr/menu.lua | 71 ------------------------------------------------------- 4 files changed, 72 insertions(+), 73 deletions(-) create mode 100644 lua/cfgmenu.lua delete mode 100644 lua/mngr/init.lua delete mode 100644 lua/mngr/menu.lua diff --git a/init.lua b/init.lua index 5e5ec85..a02d568 100644 --- a/init.lua +++ b/init.lua @@ -21,4 +21,4 @@ if pcall(require, "luasnip") then end -- call the config manager ---------------------------------------------------- -require('mngr') +require('cfgmenu') diff --git a/lua/cfgmenu.lua b/lua/cfgmenu.lua new file mode 100644 index 0000000..7335079 --- /dev/null +++ b/lua/cfgmenu.lua @@ -0,0 +1,71 @@ +-- helper functions that can come in handy ------------------------------------ +local function run(cmd) + local x = io.popen(cmd) + if not x then return 1 end + local y = x:read("*a") + x:close() + return y +end + +-- custom menu for simpler neovim managment ----------------------------------- +local function genmenu() + local list = {} + local function add(name, plug) + if not plug then + table.insert(list, name) + return + end + if package.loaded[plug] then + table.insert(list, name) + end + end + + add('edit config', nil) + add('update plugins', 'dep') + add('show keybinds', 'telescope') + add('change colorscheme', 'telescope') + add('new plugins', 'telescope') + + return list +end + +local function configmenu() + local list = genmenu() + vim.ui.select(list, { vpt = 'Config Menu' }, + function(choice) + if choice == 'edit config' then + vim.cmd('e $XDG_CONFIG_HOME/nvim/init.lua') + end + if choice == 'update plugins' then + require('dep').sync() + if package.loaded['nvim-treesitter'] then + vim.cmd('TSUpdate') + end + if package.loaded['mason'] then + require('mason.api.command').MasonUpdate() + end + end + if choice == 'show keybinds' then + require('telescope.builtin').keymaps() + end + if choice == 'change colorscheme' then + vim.cmd("Colorscheme") + end + -- search though plugins (powered by nvim.sh) + if choice == 'new plugins' then + local result = run("curl -s https://nvim.sh/s") + local array = {} + for s in string.gmatch(result, "[^\r\n]+") do + table.insert(array, s) + end + local header = table.remove(array, 1) + vim.ui.select(array, { vpt = header }, function(choice) + end) + end + end) +end + +vim.keymap.set('n', 'm', configmenu, { + desc = "Neovim config manager menu", +}) +vim.api.nvim_create_user_command("ConfigMenu", configmenu, {}) diff --git a/lua/mngr/init.lua b/lua/mngr/init.lua deleted file mode 100644 index 37a7c03..0000000 --- a/lua/mngr/init.lua +++ /dev/null @@ -1 +0,0 @@ -require('mngr.menu') diff --git a/lua/mngr/menu.lua b/lua/mngr/menu.lua deleted file mode 100644 index 8930043..0000000 --- a/lua/mngr/menu.lua +++ /dev/null @@ -1,71 +0,0 @@ --- helper functions that can come in handy -local function run(cmd) - local x = io.popen(cmd) - local y = x:read("*a") - x:close() - return y -end - --- custom menu for simpler neovim managment ----------------------------------- -local function genmenu() - local list = {} - local function add(name, plug) - if not plug then - table.insert(list, name) - return - end - if package.loaded[plug] then - table.insert(list, name) - end - end - - add('edit config', nil) - add('update plugins', 'dep') - add('update config', nil) - add('show keybinds', 'telescope') - add('change colorscheme', 'telescope') - add('new plugins', 'telescope') - - return list -end - -local function configmenu() - local list = genmenu() - - vim.ui.select(list, { vpt = 'Config Menu' }, - function(choice) - if choice == 'edit config' then - vim.cmd('e $XDG_CONFIG_HOME/nvim/init.lua') - end - if choice == 'update plugins' then - require('dep').sync() - if package.loaded['nvim-treesitter'] then - vim.cmd('TSUpdate') - end - if package.loaded['mason'] then - require('mason.api.command').MasonUpdate() - end - end - if choice == 'update config' then - require('mngr.updates') - end - if choice == 'show keybinds' then - require('telescope.builtin').keymaps() - end - if choice == 'change colorscheme' then - require('telescope.builtin').colorscheme() - end - -- search though plugins (powered by nvim.sh) - if choice == 'new plugins' then - local result = run("curl -s https://nvim.sh/s") - local array = {} - for s in string.gmatch(result, "[^\r\n]+") do - table.insert(array, s) - end - local header = table.remove(array, 1) - vim.ui.select(array, { vpt = header}, function() end) - end - end) -end - -vim.keymap.set('n', 'm', configmenu, {}) -- cgit v1.2.1