updates
This commit is contained in:
3
lua/utils/extensions/init.lua
Normal file
3
lua/utils/extensions/init.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
return {
|
||||
require("utils.extensions.telescope"),
|
||||
}
|
||||
7
lua/utils/extensions/telescope/init.lua
Normal file
7
lua/utils/extensions/telescope/init.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
local ts = require("telescope")
|
||||
ts.load_extension("fzf")
|
||||
ts.load_extension("color_names")
|
||||
ts.load_extension("file_browser")
|
||||
ts.load_extension("glyph")
|
||||
ts.load_extension("ui-select")
|
||||
ts.load_extension("noice")
|
||||
57
lua/utils/git_paste/init.lua
Normal file
57
lua/utils/git_paste/init.lua
Normal file
@@ -0,0 +1,57 @@
|
||||
local M = {}
|
||||
|
||||
--- Fetches the content from the given URL and then pastes the contents below the current line.
|
||||
---@param url string The URL to fetch (expects a Git raw URL).
|
||||
function M.fetch_and_paste(url)
|
||||
if not url or url == "" then
|
||||
vim.notify("git-paste: No URL provided.", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
-- Use curl to fetch the raw file content
|
||||
local result = vim.fn.system({ "curl", "-s", url })
|
||||
|
||||
if vim.v.shell_error ~= 0 then
|
||||
vim.notify("git-paste: Failed to fetch content from URL:\n" .. result, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
-- Split the result into lines. This creates a table with each line.
|
||||
local lines = vim.split(result, "\n")
|
||||
|
||||
-- Get the current cursor position. This returns a table {line, col}
|
||||
-- Nvim's API for setting lines expects 0-indexed line numbers.
|
||||
local pos = vim.api.nvim_win_get_cursor(0)
|
||||
-- Insert the fetched lines after the current cursor line.
|
||||
-- Since pos[1] is 1-indexed, we use it directly as the insertion index (which is 0-indexed)
|
||||
-- when inserting *after* the current line.
|
||||
local insert_at = pos[1]
|
||||
vim.api.nvim_buf_set_lines(0, insert_at, insert_at, false, lines)
|
||||
|
||||
vim.notify("git-paste: Content pasted successfully", vim.log.levels.INFO)
|
||||
end
|
||||
|
||||
--- Prompts the user for a Git raw URL and then pastes the fetched content.
|
||||
function M.git_paste_prompt()
|
||||
vim.ui.input({ prompt = "Git raw URL: " }, function(input)
|
||||
if input then
|
||||
M.fetch_and_paste(input)
|
||||
else
|
||||
vim.notify("git-paste: No URL provided", vim.log.levels.WARN)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--- Sets up the git-paste module.
|
||||
---
|
||||
--- The module expects an optional configuration table:
|
||||
--- { telescope_key = "<leader>pg" } (or any other keymap you prefer)
|
||||
---
|
||||
---@param opts table|nil
|
||||
function M.setup(opts)
|
||||
opts = opts or {}
|
||||
local telescope_key = opts.telescope_key or "<leader>pg"
|
||||
vim.keymap.set("n", telescope_key, M.git_paste_prompt, { desc = "Git Paste: paste content from git raw URL" })
|
||||
end
|
||||
|
||||
return M
|
||||
12
lua/utils/keymaps/converters/from_table/init.lua
Normal file
12
lua/utils/keymaps/converters/from_table/init.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local M = {}
|
||||
local map = vim.keymap.set
|
||||
local opts = { noremap = true, silent = true }
|
||||
|
||||
function M.set_keybindings(bindings)
|
||||
for _, binding in ipairs(bindings) do
|
||||
map(binding.mode, binding.key, binding.cmd, binding.opts or opts)
|
||||
end
|
||||
return bindings
|
||||
end
|
||||
|
||||
return M
|
||||
48
lua/utils/keymaps/converters/whichkey/init.lua
Normal file
48
lua/utils/keymaps/converters/whichkey/init.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
local M = {}
|
||||
|
||||
local whichkey = require("which-key")
|
||||
vim.notify = require("notify")
|
||||
|
||||
---Helper function to add mappings to which-key
|
||||
---@parm mappings table : List of mappings to add to which-key
|
||||
---@parm group table : Group to add mappings to (optional)
|
||||
---@return nil
|
||||
---@usage addToWhichKey(mappings, group)
|
||||
---@example addToWhichKey({{key = "n", cmd = "next", mode = "n", desc = "Next Line", group = "Navigation"}, {key = "t", group = "example"})
|
||||
function M.addToWhichKey(mappings, group)
|
||||
local wk_mappings = {}
|
||||
if group then
|
||||
whichkey.add({ group.key, group = group.group })
|
||||
end
|
||||
if not mappings and not group then
|
||||
vim.notify("Error: Mappings is nil", "error")
|
||||
return
|
||||
elseif not mappings and group then
|
||||
return
|
||||
end
|
||||
for _, mapping in ipairs(mappings) do
|
||||
if not mapping.key or mapping.key == "" then
|
||||
vim.notify("Error: Key is empty or nil", "error")
|
||||
return
|
||||
end
|
||||
|
||||
if not mapping.cmd or mapping.cmd == "" then
|
||||
vim.notify("Error: Command is empty or nil for key: " .. mapping.key, "error")
|
||||
return
|
||||
end
|
||||
|
||||
if not mapping.mode or mapping.mode == "" then
|
||||
vim.notify("Error: Mode is empty or nil for key: " .. mapping.key, "error")
|
||||
return
|
||||
end
|
||||
|
||||
wk_mappings[1] = mapping.key
|
||||
wk_mappings[2] = mapping.cmd
|
||||
wk_mappings.mode = mapping.mode
|
||||
wk_mappings.desc = mapping.desc or "No Description"
|
||||
wk_mappings.group = mapping.group or "No Group"
|
||||
whichkey.add(wk_mappings)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
4
lua/utils/keymaps/init.lua
Normal file
4
lua/utils/keymaps/init.lua
Normal file
@@ -0,0 +1,4 @@
|
||||
return {
|
||||
require('utils.keymaps.converters.whichkey'),
|
||||
require('utils.keymaps.converters.from_table'),
|
||||
}
|
||||
68
lua/utils/telescope_extra/init.lua
Normal file
68
lua/utils/telescope_extra/init.lua
Normal file
@@ -0,0 +1,68 @@
|
||||
local telescope = require("telescope")
|
||||
local telescopeConfig = require("telescope.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
function M.setup()
|
||||
-- Clone the default Telescope configuration
|
||||
local vimgrep_arguments = { unpack(telescopeConfig.values.vimgrep_arguments) }
|
||||
|
||||
-- I want to search in hidden/dot files.
|
||||
table.insert(vimgrep_arguments, "--hidden")
|
||||
-- I don't want to search in the `.git` directory.
|
||||
table.insert(vimgrep_arguments, "--glob")
|
||||
table.insert(vimgrep_arguments, "!**/.git/*")
|
||||
telescope.setup({
|
||||
defaults = {
|
||||
-- `hidden = true` is not supported in text grep commands.
|
||||
vimgrep_arguments = vimgrep_arguments,
|
||||
},
|
||||
pickers = {
|
||||
find_files = {
|
||||
-- `hidden = true` will still show the inside of `.git/` as it's not `.gitignore`d.
|
||||
find_command = { "rg", "--files", "--hidden", "--glob", "!**/.git/*" },
|
||||
mappings = {
|
||||
n = {
|
||||
["cd"] = function(prompt_bufnr)
|
||||
local selection = require("telescope.actions.state").get_selected_entry()
|
||||
local dir = vim.fn.fnamemodify(selection.path, ":p:h")
|
||||
require("telescope.actions").close(prompt_bufnr)
|
||||
-- Depending on what you want put `cd`, `lcd`, `tcd`
|
||||
vim.cmd(string.format("silent lcd %s", dir))
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
preview = {
|
||||
-- show images in telescope using kitty
|
||||
mime_hook = function(filepath, bufnr, opts)
|
||||
local is_image = function(filepath)
|
||||
local image_extensions = { "png", "jpg" } -- Supported image formats
|
||||
local split_path = vim.split(filepath:lower(), ".", { plain = true })
|
||||
local extension = split_path[#split_path]
|
||||
return vim.tbl_contains(image_extensions, extension)
|
||||
end
|
||||
if is_image(filepath) then
|
||||
local term = vim.api.nvim_open_term(bufnr, {})
|
||||
local function send_output(_, data, _)
|
||||
for _, d in ipairs(data) do
|
||||
vim.api.nvim_chan_send(term, d .. "\r\n")
|
||||
end
|
||||
end
|
||||
vim.fn.jobstart({
|
||||
"kitty +icat " .. filepath, -- Terminal image viewer command
|
||||
}, { on_stdout = send_output, stdout_buffered = true, pty = true })
|
||||
else
|
||||
require("telescope.previewers.utils").set_preview_message(
|
||||
bufnr,
|
||||
opts.winid,
|
||||
"Binary cannot be previewed"
|
||||
)
|
||||
end
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
6
lua/utils/terminal/init.lua
Normal file
6
lua/utils/terminal/init.lua
Normal file
@@ -0,0 +1,6 @@
|
||||
local M = {}
|
||||
|
||||
M.term_factory = require("utils.terminal.term_factory").term_factory
|
||||
M.term_toggle = require("utils.terminal.toggle").term_toggle
|
||||
|
||||
return M
|
||||
12
lua/utils/terminal/term_factory/init.lua
Normal file
12
lua/utils/terminal/term_factory/init.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local Terminal = require("toggleterm.terminal").Terminal
|
||||
local notify = require("notify")
|
||||
local M = {}
|
||||
|
||||
function M.term_factory(cfg)
|
||||
cfg["on_stderr"] = function(_, job, data, name)
|
||||
notify(name .. " encountered an error on job: " .. job .. "\nData: " .. data, "error")
|
||||
end
|
||||
return Terminal:new(cfg)
|
||||
end
|
||||
|
||||
return M
|
||||
9
lua/utils/terminal/toggle/init.lua
Normal file
9
lua/utils/terminal/toggle/init.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
local M = {}
|
||||
|
||||
function M.term_toggle(term)
|
||||
if term then
|
||||
term:toggle()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user