summaryrefslogtreecommitdiffstats
path: root/lua/mngr/menu.lua
blob: 958c4667d139b46a618823ebee8488780c3aae78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-- 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')

  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
      if choice == 'show keybinds' then
        require('telescope.builtin').keymaps()
      end
    end
  end)
end

vim.keymap.set('n', '<C-m>', configmenu, {})