dotfiles/vim/lua/commands.lua

62 lines
1.7 KiB
Lua
Raw Normal View History

2023-09-17 17:43:16 +00:00
function _G.dump(...)
2023-09-19 05:21:43 +00:00
local objects = vim.tbl_map(vim.inspect, { ... })
print(unpack(objects))
return ...
2023-09-17 17:43:16 +00:00
end
function _G.insert_uuid()
2023-09-19 05:21:43 +00:00
local uuid = vim.fn.system("uuidprint")
local errcode = vim.v.shell_error
if errcode ~= 0 then
vim.api.nvim_err_writeln("uuidprint returned error code: " .. errcode)
return
end
vim.fn.setreg("u", uuid)
vim.api.nvim_command([[normal! "up]])
2023-09-17 17:43:16 +00:00
end
2023-09-19 05:21:43 +00:00
vim.api.nvim_set_keymap("n", "<leader>pu", [[:lua _G.insert_uuid()<cr>]], { noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<c-d><c-u>", [[<esc>:lua _G.insert_uuid()<cr>a]], { noremap = true, silent = true })
2023-09-17 17:43:16 +00:00
function _G.insert_jira_url()
2023-09-19 05:21:43 +00:00
local url = vim.fn.system("jira")
local errcode = vim.v.shell_error
if errcode ~= 0 then
vim.api.nvim_err_writeln("jira returned error code: " .. errcode)
return
end
vim.fn.setreg("u", url)
vim.api.nvim_command([[normal! "up]])
2023-09-17 17:43:16 +00:00
end
2023-09-19 05:21:43 +00:00
vim.api.nvim_set_keymap("n", "<leader>pj", [[:lua _G.insert_jira_url()<cr>]], { noremap = true, silent = true })
vim.api.nvim_set_keymap("i", "<c-d><c-j>", [[<esc>:lua _G.insert_jira_url()<cr>a]], { noremap = true, silent = true })
2023-09-17 17:43:16 +00:00
function _G.insert_iso8601_timestamp()
2023-09-19 05:21:43 +00:00
local ts = vim.fn.system("echo -n $(date --iso-8601=seconds)")
2023-09-17 17:43:16 +00:00
2023-09-19 05:21:43 +00:00
local errcode = vim.v.shell_error
if errcode ~= 0 then
vim.api.nvim_err_writeln("date returned error code: " .. errcode)
return
end
2023-09-17 17:43:16 +00:00
2023-09-19 05:21:43 +00:00
vim.fn.setreg("u", ts)
vim.api.nvim_command([[normal! "up]])
2023-09-17 17:43:16 +00:00
end
2023-09-19 05:21:43 +00:00
vim.api.nvim_set_keymap(
"n",
"<leader>pt",
[[:lua _G.insert_iso8601_timestamp()<cr>]],
{ noremap = true, silent = true }
)
vim.api.nvim_set_keymap(
"i",
"<c-d><c-t>",
[[<esc>:lua _G.insert_iso8601_timestamp()<cr>a]],
{ noremap = true, silent = true }
)