Skip to content

[Feature] Make --data-binary body size threshold configurable in copy() function #821

@sahidvelji

Description

@sahidvelji

Is your feature request related to a problem? Please describe.

When using the copy() function to copy a request as a cURL command, the body content is replaced with a file reference (@filename) if it exceeds 1000 characters. This threshold is hardcoded and cannot be configured by the user.

This can be frustrating when:

  • You want to always inline the body regardless of size for portability
  • You need to share curl commands with others who don't have access to the referenced file

Describe the solution you'd like

Make the body size threshold configurable via the plugin's opts configuration. For example:

require("kulala").setup({
  copy = {
    body_max_size = 1000, -- default: 1000, set to -1 to always inline
  }
})

The relevant code is in [lua/kulala/ui/init.lua at line 558](https://github.com/mistweaverco/kulala.nvim/blob/main/lua/kulala/ui/init.lua#L558):

body = #body > 1000 and flag or body

This should reference a config value instead of the hardcoded 1000.

Additional context

The copy() function is defined at lua/kulala/ui/init.lua:543-568. The specific logic that determines whether to use the file reference or inline body is:

if previous_flag == "--data-binary" or previous_flag == "--data-urlencode" then
  local body = FS.read_file(flag:sub(2), true) or "[could not read file]"
  body = #body > 1000 and flag or body  -- <-- hardcoded threshold
  cmd = ("%s%s %s "):format(cmd, previous_flag, vim.fn.shellescape(body))
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions