Initial new commit
This commit is contained in:
commit
c46ad3d427
22 changed files with 2401 additions and 0 deletions
168
lua/config/commands.lua
Executable file
168
lua/config/commands.lua
Executable file
|
@ -0,0 +1,168 @@
|
|||
local pickers = require "telescope.pickers"
|
||||
local finders = require "telescope.finders"
|
||||
local conf = require("telescope.config").values
|
||||
local actions = require "telescope.actions"
|
||||
local action_state = require "telescope.actions.state"
|
||||
|
||||
vim.api.nvim_create_user_command("OP", function()
|
||||
local folders = vim.fn.systemlist("\\ls -d $HOME/projects/*/")
|
||||
for i, folder in ipairs(folders) do
|
||||
folders[i] = string.match(string.match(folder, "[^/]*/$"), "^[^/]*")
|
||||
end
|
||||
pickers.new({}, {
|
||||
prompt_title = "Open project",
|
||||
finder = finders.new_table {
|
||||
results = folders
|
||||
},
|
||||
sorter = conf.generic_sorter({}),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
selection = selection[1]
|
||||
vim.cmd("cd $HOME/projects/" .. selection)
|
||||
end)
|
||||
return true
|
||||
end
|
||||
}):find()
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command("OD", function()
|
||||
local folders = vim.fn.systemlist("\\ls -d */")
|
||||
for i, folder in ipairs(folders) do
|
||||
folders[i] = string.match(string.match(folder, "[^/]*/$"), "^[^/]*")
|
||||
end
|
||||
pickers.new({}, {
|
||||
prompt_title = "Open directory",
|
||||
finder = finders.new_table {
|
||||
results = folders
|
||||
},
|
||||
sorter = conf.generic_sorter({}),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
selection = selection[1]
|
||||
vim.cmd("cd " .. selection)
|
||||
end)
|
||||
return true
|
||||
end
|
||||
}):find()
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command("Config", function()
|
||||
vim.cmd("cd $HOME/.config/nvim")
|
||||
end, {})
|
||||
|
||||
vim.api.nvim_create_user_command("RetabFile2Spaces", function()
|
||||
vim.cmd(":set ts=2 sts=2 noet | retab! | set ts=4 sts=4 et | retab!")
|
||||
end, {})
|
||||
vim.api.nvim_create_user_command("RetabFile4SpacesToTab", function()
|
||||
vim.cmd(":set ts=4 sts=4 noet | retab! | set ts=4 sts=0 noexpandtab | retab!")
|
||||
end, {})
|
||||
|
||||
local function get_makefile_targets()
|
||||
local makefile = "./Makefile"
|
||||
local targets = {}
|
||||
|
||||
local file = io.open(makefile, "r")
|
||||
if file then
|
||||
for line in file:lines() do
|
||||
local target = line:match("^[^\\s:]+:.*")
|
||||
if target then
|
||||
local tg = target:match("^[^:]+")
|
||||
table.insert(targets, tg)
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
return targets
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("Make", function(args)
|
||||
local vimCmd = "TermExec cmd=\"make"
|
||||
if (args["args"]) then
|
||||
vimCmd = vimCmd .. " " .. args["args"]
|
||||
end
|
||||
vimCmd = vimCmd .. "\""
|
||||
vim.cmd(vimCmd)
|
||||
end, {
|
||||
nargs = "*",
|
||||
["complete"] = function()
|
||||
return get_makefile_targets()
|
||||
end
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("Maket", function()
|
||||
local targets = get_makefile_targets()
|
||||
pickers.new({}, {
|
||||
prompt_title = "Run make target",
|
||||
finder = finders.new_table {
|
||||
results = targets
|
||||
},
|
||||
sorter = conf.generic_sorter({}),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
selection = selection[1]
|
||||
vim.cmd(":Make " .. selection)
|
||||
end)
|
||||
return true
|
||||
end
|
||||
}):find()
|
||||
end, {})
|
||||
|
||||
function get_just_targets()
|
||||
local handle = io.popen("just --summary")
|
||||
local res = handle:read("*a")
|
||||
handle:close()
|
||||
local targets = {}
|
||||
-- insert space seperated targets
|
||||
for target in string.gmatch(res, "%S+") do
|
||||
table.insert(targets, target)
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command("Just", function(args)
|
||||
local vimCmd = "TermExec cmd=\"just"
|
||||
if (args["args"]) then
|
||||
vimCmd = vimCmd .. " " .. args["args"]
|
||||
end
|
||||
vimCmd = vimCmd .. "\""
|
||||
vim.cmd(vimCmd)
|
||||
end, {
|
||||
nargs = "*",
|
||||
["complete"] = function()
|
||||
return get_just_targets()
|
||||
end
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command("Justt", function()
|
||||
local targets = get_makefile_targets()
|
||||
pickers.new({}, {
|
||||
prompt_title = "Run just target",
|
||||
finder = finders.new_table {
|
||||
results = targets
|
||||
},
|
||||
sorter = conf.generic_sorter({}),
|
||||
attach_mappings = function(prompt_bufnr, map)
|
||||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = action_state.get_selected_entry()
|
||||
selection = selection[1]
|
||||
vim.cmd(":Just " .. selection)
|
||||
end)
|
||||
return true
|
||||
end
|
||||
}):find()
|
||||
end, {})
|
||||
|
||||
|
||||
vim.api.nvim_create_autocmd('TextYankPost', {
|
||||
desc = 'Highlight when yanking (copying) text',
|
||||
group = vim.api.nvim_create_augroup('HightlightYank', { clear = true }),
|
||||
callback = function()
|
||||
vim.highlight.on_yank()
|
||||
end,
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue