add copy operations for relative path and directory path
parent
59945bc1c9
commit
45da137f2f
|
|
@ -66,6 +66,9 @@ The following applies to all commands above:
|
|||
- `.trashFile{trashLocation = "/your/path/"}` or `:Trash`: Move the current file to the trash location. [Defaults to the operating-system-specific trash directory.](https://github.com/chrisgrieser/nvim-genghis/blob/main/lua/genghis.lua#L164) ⚠️ Any existing file in the trash location with the same name is overwritten, making that file irretrievable. If [bufdelete.nvim](https://github.com/famiu/bufdelete.nvim) is available, `require'bufdelete.nvim'.bufwipeout` would be used to keep window layout intact instead of `vim.cmd.bwipeout`.
|
||||
- `.copyFilename` or `:CopyFilename`: Copy the file name. When `clipboard="unnamed[plus]"` has been set, copies to the `+` register, otherwise to `"`.
|
||||
- `.copyFilepath` or `:CopyFilepath`: Copy the absolute file path. When `clipboard="unnamed[plus]"` has been set, copies to the `+` register, otherwise to `"`.
|
||||
- `.copyRelativePath` or `:CopyRelativePath`: Copy the relative file path. When `clipboard="unnamed[plus]"` has been set, copies to the `+` register, otherwise to `"`.
|
||||
- `.copyDirectoryPath` or `:CopyDirectoryPath`: Copy the absolute directory path. When `clipboard="unnamed[plus]"` has been set, copies to the `+` register, otherwise to `"`.
|
||||
- `.copyRelativeDirectoryPath` or `:CopyRelativeDirectoryPath`: Copy the relative directory path. When `clipboard="unnamed[plus]"` has been set, copies to the `+` register, otherwise to `"`.
|
||||
- `.chmodx` or `:Chmodx`: Makes current file executable. Equivalent to `chmod +x`.
|
||||
|
||||
### Disable Ex-Commands
|
||||
|
|
|
|||
|
|
@ -152,24 +152,31 @@ function M.moveSelectionToNewFile() fileOp("newFromSel") end
|
|||
|
||||
---copying file information
|
||||
---@param operation string filename|filepath
|
||||
local function copyOp(operation)
|
||||
local function copyOp(expandOperation)
|
||||
local reg = '"'
|
||||
local clipboardOpt = vim.opt.clipboard:get()
|
||||
local useSystemClipb = #clipboardOpt > 0 and clipboardOpt[1]:find("unnamed")
|
||||
if useSystemClipb then reg = "+" end
|
||||
|
||||
local toCopy = expand("%:p")
|
||||
if operation == "filename" then toCopy = expand("%:t") end
|
||||
|
||||
local toCopy = expand(expandOperation)
|
||||
fn.setreg(reg, toCopy)
|
||||
vim.notify(toCopy, vim.log.levels.INFO, { title = "Copied" })
|
||||
end
|
||||
|
||||
---Copy absolute path of current file
|
||||
function M.copyFilepath() copyOp("filepath") end
|
||||
function M.copyFilepath() copyOp("%:p") end
|
||||
|
||||
---Copy name of current file
|
||||
function M.copyFilename() copyOp("filename") end
|
||||
function M.copyFilename() copyOp("%:t") end
|
||||
|
||||
---Copy relative path of current file
|
||||
function M.copyRelativePath() copyOp("%:~:.") end
|
||||
|
||||
---Copy absolute directory path of current file
|
||||
function M.copyDirectoryPath() copyOp("%:p:h") end
|
||||
|
||||
---Copy relative directory path of current file
|
||||
function M.copyRelativeDirectoryPath() copyOp("%:~:.:h") end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,9 @@ if not vim.g.genghis_disable_commands then
|
|||
command("Move", function() genghis.moveAndRenameFile() end, {})
|
||||
command("CopyFilename", function() genghis.copyFilename() end, {})
|
||||
command("CopyFilepath", function() genghis.copyFilepath() end, {})
|
||||
command("CopyRelativePath", function() genghis.copyRelativePath() end, {})
|
||||
command("CopyDirectoryPath", function() genghis.copyDirectoryPath() end, {})
|
||||
command("CopyRelativeDirectoryPath", function() genghis.copyRelativeDirectoryPath() end, {})
|
||||
command("Chmodx", function() genghis.chmodx() end, {})
|
||||
command("New", function() genghis.createNewFile() end, {})
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue