File tree Expand file tree Collapse file tree 4 files changed +28
-2
lines changed
Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 7878 jump_to_request = false ,
7979 env_file = ' .env' ,
8080 custom_dynamic_variables = {},
81+ yank_dry_run = true ,
8182 })
8283 end
8384}
Original file line number Diff line number Diff 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
6970In this section we will be using `https://reqres.in/` for requests.
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -114,13 +114,36 @@ local function create_callback(method, url)
114114 end
115115end
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
120137M .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 ))
You can’t perform that action at this time.
0 commit comments