From aa5717f00fd14430c80939a68d7107c26de6e554 Mon Sep 17 00:00:00 2001 From: Mohammad Reza Karimi Date: Tue, 20 Jan 2026 15:55:27 -0500 Subject: first commit --- lua/mo/oil-util.lua | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 lua/mo/oil-util.lua (limited to 'lua/mo/oil-util.lua') diff --git a/lua/mo/oil-util.lua b/lua/mo/oil-util.lua new file mode 100644 index 0000000..1b00fa7 --- /dev/null +++ b/lua/mo/oil-util.lua @@ -0,0 +1,67 @@ +local M = {} + +local notif = require("mo.notif") + +---@param opts { full_path: boolean } +M.copy_to_clipboard = function(opts) + opts = opts or { full_path = true } + + local oil = require("oil") + local dir = oil.get_current_dir() + if not dir then + notif.err("System clipboard only works for local files") + return + end + + local entries = {} + local mode = vim.api.nvim_get_mode().mode + if mode == "v" or mode == "V" then + local start = vim.fn.getpos("v") + local end_ = vim.fn.getpos(".") + local start_row = start[2] + local end_row = end_[2] + + if start_row > end_row then + start_row, end_row = end_row, start_row + end + + for i = start_row, end_row do + table.insert(entries, oil.get_entry_on_line(0, i)) + end + + vim.api.nvim_feedkeys( + vim.api.nvim_replace_termcodes("", true, false, true), + "n", + true + ) + else + table.insert(entries, oil.get_cursor_entry()) + end + + -- This removes holes in the list-like table + entries = vim.tbl_values(entries) + + if #entries == 0 then + vim.notify( + "Could not find local file under cursor", + vim.log.levels.WARN + ) + return + end + local paths = {} + for _, entry in ipairs(entries) do + if opts.full_path then + table.insert(paths, dir .. entry.name) + else + table.insert(paths, entry.name) + end + end + require("vim.ui.clipboard.osc52").copy("+")(paths) + if #paths == 1 then + notif.info(string.format("Copied '%s' to system clipboard", paths[1])) + else + notif.info(string.format("Copied %d files to system clipboard", #paths)) + end +end + +return M -- cgit v1.2.3-71-gdd5e