Skip to content

Commit b635ff2

Browse files
purefunNTBBloodbath
authored andcommitted
feat: yank executable curl cmd
1 parent 4b8608e commit b635ff2

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use {
7878
jump_to_request = false,
7979
env_file = '.env',
8080
custom_dynamic_variables = {},
81+
yank_dry_run = true,
8182
})
8283
end
8384
}

doc/rest-nvim.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function, it looks like this by default:
6363
` },`
6464
` -- Jump to request line on run`
6565
` jump_to_request = false,`
66-
` env_file = '.env'`
66+
` env_file = '.env',`
67+
` yank_dry_run = true,`
6768
`})`
6869

6970
In this section we will be using `https://reqres.in/` for requests.

lua/rest-nvim/config/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ local config = {
1515
jump_to_request = false,
1616
env_file = ".env",
1717
custom_dynamic_variables = {},
18+
yank_dry_run = true,
1819
}
1920

2021
--- Get a configuration value

lua/rest-nvim/curl/init.lua

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,36 @@ local function create_callback(method, url)
114114
end
115115
end
116116

117+
local function format_curl_cmd(res)
118+
local cmd = 'curl'
119+
120+
for _, value in pairs(res) do
121+
if string.sub(value, 1, 1) == '-' then
122+
cmd = cmd .. ' ' .. value
123+
else
124+
cmd = cmd .. " '" .. value .. "'"
125+
end
126+
end
127+
128+
-- remote -D option
129+
cmd = string.gsub(cmd, "-D '%S+' ", "")
130+
return cmd
131+
end
132+
133+
117134
-- curl_cmd runs curl with the passed options, gets or creates a new buffer
118135
-- and then the results are printed to the recently obtained/created buffer
119136
-- @param opts curl arguments
120137
M.curl_cmd = function(opts)
121138
if opts.dry_run then
122139
local res = curl[opts.method](opts)
123-
log.debug("[rest.nvim] Request preview:\n" .. "curl " .. table.concat(res, " "))
140+
local curl_cmd = format_curl_cmd(res)
141+
142+
if config.get('yank_dry_run') then
143+
vim.cmd('let @+="' .. curl_cmd .. '"')
144+
end
145+
146+
log.debug("[rest.nvim] Request preview:\n" .. curl_cmd)
124147
return
125148
else
126149
opts.callback = vim.schedule_wrap(create_callback(opts.method, opts.url))

0 commit comments

Comments
 (0)