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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
local pickers = require("telescope.pickers")
local finders = require("telescope.finders")
local previewers = require("telescope.previewers")
local conf = require("telescope.config").values
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local M = {}
local function genmenu()
local list = {}
local function add(name, plug)
if not plug then
table.insert(list, name)
elseif package.loaded[plug] then
table.insert(list, name)
end
end
add('Edit Config', nil)
add('Update Plugins', 'dep')
add('Keybinds', 'telescope')
add('Colorscheme', 'telescope')
return list
end
function M.configmenu()
pickers.new({
prompt_title = "Nvim Config Menu",
finder = finders.new_table { results = genmenu() },
sorter = conf.generic_sorter(),
previewer = previewers.new_buffer_previewer {
define_preview = function(self, entry)
local lines = {
'a'
}
if entry.value == "Edit Config" then
lines = misc.readf(vim.fn.stdpath('config')..'/init.lua')
local ft = vim.filetype.match({
filename = os.getenv('XDG_CONFIG_HOME')..'/nvim/init.lua' })
require("telescope.previewers.utils").highlighter(self.state.bufnr, ft)
elseif entry.value == "Colorscheme" then
lines = vim.fn.getcompletion('', 'color')
for k, v in pairs(lines) do
if v.find(v, '.ext') then
table.remove(lines, k)
break
end
end
end
vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, lines)
end
},
attach_mappings = function(bufnr, map)
actions.select_default:replace(function()
actions.close(bufnr)
local selection = action_state.get_selected_entry()
if selection[1] == 'Edit Config' then
vim.cmd('e '..vim.fn.stdpath('config')..'/init.lua')
elseif selection[1] == '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
elseif selection[1] == 'Keybinds' then
require('telescope.builtin').keymaps()
elseif selection[1] == 'Colorscheme' then
require('core.theme').switcher()
end
end)
return true
end,
}):find()
end
return M
|