feat!: on macos, consider iCloud trash
parent
5972ad4c77
commit
3ead1e4086
|
|
@ -51,23 +51,24 @@ keymap("x", "<leader>x", genghis.moveSelectionToNewFile)
|
|||
- `.moveAndRenameFile` or `:Move`: Move and Rename the current file. Works like the UNIX `mv` command. Best used with [autocompletion of directories](#autocompletion-of-directories).
|
||||
|
||||
> __Note__
|
||||
> Applying to all commands above:
|
||||
> The following applies to all commands above:
|
||||
> - If no extension has been provided, will use the extension of the original file.
|
||||
> - If the new file name includes a `/`, the new file is placed in the respective subdirectory, creating any non-existing folders. Except for `.moveAndRenameFile`, all operations take only place in the current working directory, so `.moveAndRenameFile` is the only command that can move to a parent directory.
|
||||
> - All commands support [autocompletion of existing directories](#autocompletion-of-directories).
|
||||
|
||||
- `.trashFile{trashLocation = "your/path/"}` or `:Trash`: Move the current file the trash location. Defaults to location is `$HOME/.Trash/`. ⚠️ Any existing file in the trash location with the same name is overwritten, making that file irretrievable.
|
||||
- `.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.
|
||||
- `.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 `"`.
|
||||
- `.chmodx` or `:Chmodx`: Makes current file executable. Equivalent to `chmod +x`.
|
||||
|
||||
### How to disable command-line commands
|
||||
Put this in your configuration file:
|
||||
|
||||
```lua
|
||||
-- lua
|
||||
vim.g.genghis_disable_commands = true
|
||||
```
|
||||
or
|
||||
|
||||
```vim
|
||||
-- viml
|
||||
let g:genghis_disable_commands = v:true
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ local function fileOp(op)
|
|||
end
|
||||
|
||||
-- selene: allow(high_cyclomatic_complexity)
|
||||
-- INFO completion = "dir" allows for completion via cmp-omni
|
||||
vim.ui.input({ prompt = promptStr, default = prefill, completion = "dir" }, function(newName)
|
||||
-- validation
|
||||
local invalidName = false
|
||||
|
|
@ -160,21 +161,27 @@ end
|
|||
function M.trashFile(opts)
|
||||
cmd.update { bang = true }
|
||||
local trash
|
||||
local home = os.getenv("HOME")
|
||||
|
||||
if vim.fn.has('linux') == 1 then
|
||||
-- Default trash locations
|
||||
if fn.has("linux") or fn.has("unix") then
|
||||
local xdg_data = os.getenv("XDG_DATA_HOME")
|
||||
if xdg_data then
|
||||
trash = xdg_data .. "/Trash/"
|
||||
else
|
||||
trash = os.getenv("HOME") .. "/.local/share/Trash/"
|
||||
end
|
||||
trash = xdg_data and xdg_data .. "/trash" or home .. "/.local/share/Trash"
|
||||
elseif fn.has("macunix") then
|
||||
-- INFO macOS moves files to the icloud trash, if they are deleted from
|
||||
-- icloud folder, otherwise they go the user trash folder
|
||||
local iCloudPath = home .. "/Library/Mobile Documents/com~apple~CloudDocs"
|
||||
local isInICloud = fn.expand("%:p:h"):sub(1, #iCloudPath) == iCloudPath
|
||||
trash = isInICloud and iCloudPath .. "/Trash/" or home .. "/.Trash/"
|
||||
else
|
||||
trash = os.getenv("HOME") .. "/.Trash/"
|
||||
-- TODO: support windows
|
||||
trash = home .. "/.Trash/"
|
||||
end
|
||||
|
||||
-- overwrite trash location, if specified by user
|
||||
if opts and opts.trashLocation then
|
||||
trash = opts.trashLocation
|
||||
if not (trash:find("/$")) then trash = trash .. "/" end
|
||||
if not (trash:find("/$")) then trash = trash .. "/" end -- append "/"
|
||||
end
|
||||
|
||||
local currentFile = expand("%:p")
|
||||
|
|
|
|||
Loading…
Reference in New Issue