diff --git a/README.md b/README.md index 519d792..7ce0747 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,9 @@ Lightweight and quick file operations without being a full-blown file manager. - [Features](#features) -- [Installation and Setup](#installation-and-setup) +- [Installation](#installation) +- [Configuration](#configuration) +- [Usage](#usage) - [Available Commands](#available-commands) * [File Operation Commands](#file-operation-commands) * [Utility Commands](#utility-commands) @@ -32,7 +34,7 @@ Lightweight and quick file operations without being a full-blown file manager. when no extension is given, or the ability to use vim motions in the input field. -## Installation and Setup +## Installation ```lua -- lazy.nvim @@ -42,8 +44,18 @@ Lightweight and quick file operations without being a full-blown file manager. use {"chrisgrieser/nvim-genghis", requires = "stevearc/dressing.nvim"} ``` -`nvim-genghis` (and `dressing.nvim`) require no `.setup()` function. Just create -keybindings for the commands you want to use: +## Configuration +The `setup` call is optional. + +```lua +-- default config +require("genghis").setup { + -- cli name, default is `trash` on Mac and Windows, and `gio trash` on Linux + trashCmd = "trash", +} +``` + +## Usage ```lua local keymap = vim.keymap.set @@ -84,7 +96,7 @@ The following applies to all commands above: ### Utility Commands - `.chmodx` or `:Chmodx`: Makes current file executable. Equivalent to `chmod +x`. -- `.trashFile{trashCmd = "your_cli"}` or `:Trash`: Move the current file +- `.trashFile` or `:Trash`: Move the current file to the trash location. * Defaults to `gio trash` on *Linux*, `trash` on *Mac* and *Windows*. * If [bufdelete.nvim](https://github.com/famiu/bufdelete.nvim) is available, @@ -92,7 +104,7 @@ to the trash location. intact instead of `vim.cmd.bwipeout`. > [!NOTE] -> The trash CLIs are not available by default, and must be installed. +> The trash CLIs are usually not available by default, and must be installed. ### Path Copying Commands - `.copyFilename` or `:CopyFilename`: Copy the file name. diff --git a/lua/genghis/config.lua b/lua/genghis/config.lua new file mode 100644 index 0000000..e5ebf78 --- /dev/null +++ b/lua/genghis/config.lua @@ -0,0 +1,17 @@ +local M = {} +-------------------------------------------------------------------------------- + +---@class Genghis.config +local defaultConfig = { + trashCmd = nil, +} + +M.config = defaultConfig + +---@param userConfig? Genghis.config +function M.setup(userConfig) + M.config = vim.tbl_deep_extend("force", defaultConfig, userConfig or {}) +end + +-------------------------------------------------------------------------------- +return M diff --git a/lua/genghis/init.lua b/lua/genghis/init.lua index dd4f5c3..9c5159e 100644 --- a/lua/genghis/init.lua +++ b/lua/genghis/init.lua @@ -11,6 +11,11 @@ local M = {} setmetatable(M, { __index = function(_, key) return function(...) + if key == "setup" then + require("genghis.config").setup(...) + return + end + local module = vim.startswith(key, "copy") and "copy" or "file" require("genghis.operations." .. module)[key](...) end diff --git a/lua/genghis/operations/file.lua b/lua/genghis/operations/file.lua index 1bb39d2..9b46857 100644 --- a/lua/genghis/operations/file.lua +++ b/lua/genghis/operations/file.lua @@ -190,16 +190,24 @@ function M.chmodx() vim.cmd.edit() end ----@param opts? { trashCmd: string } function M.trashFile(opts) - local userCmd = opts and opts.trashCmd - local system = vim.uv.os_uname().sysname:lower() - local defaultCmd - if system == "darwin" then defaultCmd = "trash" end - if system:find("windows") then defaultCmd = "trash" end - if system:find("linux") then defaultCmd = "gio trash" end - local trashCmd = userCmd or defaultCmd - assert(defaultCmd, "Unknown operating system. Please provide a custom trashCmd.") + ---DEPRECATION + if opts then + u.notify("The `trashCmd` option has been moved to the setup call.", "warn") + return + end + + -- user-provided trashCmd or os-specific default + local trashCmd = require("genghis.config").config.trashCmd + if not trashCmd then + local system = vim.uv.os_uname().sysname:lower() + local defaultCmd + if system == "darwin" then defaultCmd = "trash" end + if system:find("windows") then defaultCmd = "trash" end + if system:find("linux") then defaultCmd = "gio trash" end + assert(defaultCmd, "Unknown operating system. Please provide a custom `trashCmd`.") + trashCmd = defaultCmd + end local trashArgs = vim.split(trashCmd, " ") local oldFilePath = vim.api.nvim_buf_get_name(0) @@ -210,7 +218,7 @@ function M.trashFile(opts) local result = vim.system(trashArgs):wait() if result.code == 0 then u.bwipeout() - u.notify(("%q deleted"):format(oldName)) + u.notify(("%q deleted."):format(oldName)) else local outmsg = (result.stdout or "") .. (result.stderr or "") u.notify(("Trashing %q failed: " .. outmsg):format(oldName), "error")