diff --git a/README.md b/README.md index 18c8bcb..a95864f 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,9 @@ return { ## Usage The following commands are used: -- `BlameToggle [view]` - Toggle the blame with provided view. If no view is provided it opens the `default` (window) view +- `BlameToggle [view] [options]` - Toggle the blame with provided view and options. + - If no view is provided, it opens the `default` (window) view. + - If no options are provided, it fall back to `blame_options`. There are two built-in views: - `window` - fugitive style window to the left of the current window diff --git a/lua/blame.lua b/lua/blame.lua index aebf629..93324c2 100644 --- a/lua/blame.lua +++ b/lua/blame.lua @@ -57,11 +57,12 @@ local config = { } ---@param blame_view BlameView -local function open(blame_view) +---@param opts string[] | nil +local function open(blame_view, opts) local filename = vim.api.nvim_buf_get_name(0) local cwd = vim.fn.expand("%:p:h") local g = git:new(config) - g:blame(filename, cwd, nil, function(data) + g:blame(filename, cwd, nil, opts, function(data) vim.schedule(function() local parsed_blames = porcelain_parser.parse_porcelain(data) blame_view:open(parsed_blames) @@ -95,13 +96,22 @@ M.setup = function(setup_args) M.last_opened_view:close(false) M.last_opened_view = nil else - local arg = args.args == "" and "default" or args.args - blame_view = config.views[arg]:new(config) - open(blame_view) + local fargs = args.fargs + local view_name = "default" + local opts = {} + for i = 1, #fargs do + if fargs[i]:sub(1, 1) == "-" then + table.insert(opts, fargs[i]) + else + view_name = fargs[i] + end + end + blame_view = config.views[view_name]:new(config) + open(blame_view, opts) M.last_opened_view = blame_view end end, { - nargs = "?", + nargs = "*", complete = function() local all_views = {} for k, _ in pairs(config.views) do diff --git a/lua/blame/git.lua b/lua/blame/git.lua index 282f26f..2ee6b69 100644 --- a/lua/blame/git.lua +++ b/lua/blame/git.lua @@ -48,8 +48,9 @@ end ---@param filename string ---@param cwd any cwd where to execute the command ---@param commit string|nil +---@param opts string[]|nil ---@param callback fun(data: string[]) callback on exiting the command with output string -function Git:blame(filename, cwd, commit, callback, err_cb) +function Git:blame(filename, cwd, commit, opts, callback, err_cb) local blame_command = { "git", "--no-pager", @@ -57,7 +58,12 @@ function Git:blame(filename, cwd, commit, callback, err_cb) "--line-porcelain", filename, } - add_blame_options(blame_command, self.config.blame_options) + + local blame_options = self.config.blame_options + if opts ~= nil and #opts > 0 then + blame_options = opts + end + add_blame_options(blame_command, blame_options) if commit ~= nil then table.insert(blame_command, #blame_command - 1, commit) end