feat!: on macos, consider iCloud trash

remotes/origin/HEAD
pseudometa 2023-02-22 15:28:06 +01:00
parent 5972ad4c77
commit 3ead1e4086
2 changed files with 19 additions and 11 deletions

View File

@ -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). - `.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__ > __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 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. > - 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). > - 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 `"`. - `.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 `"`. - `.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`. - `.chmodx` or `:Chmodx`: Makes current file executable. Equivalent to `chmod +x`.
### How to disable command-line commands ### How to disable command-line commands
Put this in your configuration file: Put this in your configuration file:
```lua ```lua
-- lua -- lua
vim.g.genghis_disable_commands = true vim.g.genghis_disable_commands = true
``` ```
or
```vim ```vim
-- viml -- viml
let g:genghis_disable_commands = v:true let g:genghis_disable_commands = v:true

View File

@ -45,6 +45,7 @@ local function fileOp(op)
end end
-- selene: allow(high_cyclomatic_complexity) -- 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) vim.ui.input({ prompt = promptStr, default = prefill, completion = "dir" }, function(newName)
-- validation -- validation
local invalidName = false local invalidName = false
@ -160,21 +161,27 @@ end
function M.trashFile(opts) function M.trashFile(opts)
cmd.update { bang = true } cmd.update { bang = true }
local trash 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") local xdg_data = os.getenv("XDG_DATA_HOME")
if xdg_data then trash = xdg_data and xdg_data .. "/trash" or home .. "/.local/share/Trash"
trash = xdg_data .. "/Trash/" elseif fn.has("macunix") then
else -- INFO macOS moves files to the icloud trash, if they are deleted from
trash = os.getenv("HOME") .. "/.local/share/Trash/" -- icloud folder, otherwise they go the user trash folder
end 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 else
trash = os.getenv("HOME") .. "/.Trash/" -- TODO: support windows
trash = home .. "/.Trash/"
end end
-- overwrite trash location, if specified by user
if opts and opts.trashLocation then if opts and opts.trashLocation then
trash = opts.trashLocation trash = opts.trashLocation
if not (trash:find("/$")) then trash = trash .. "/" end if not (trash:find("/$")) then trash = trash .. "/" end -- append "/"
end end
local currentFile = expand("%:p") local currentFile = expand("%:p")