aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authordemotulatingswan <demotulatingswan@users.noreply.github.com>2020-06-09 22:58:49 +0200
committerdemotulatingswan <demotulatingswan@users.noreply.github.com>2020-06-09 23:00:30 +0200
commitaf453b561606c2718d4d2d9ff7d4450c26892162 (patch)
treeb0ab0fe6791fc6b1db8f7783c616f83347e52495 /plugins
parent0e8605da5c9ad371eb1f96e22f821d8c29a026e2 (diff)
downloadlite-xl-plugins-af453b561606c2718d4d2d9ff7d4450c26892162.tar.gz
lite-xl-plugins-af453b561606c2718d4d2d9ff7d4450c26892162.zip
Fixed executing multiple commands in one go with exec:replace
Diffstat (limited to 'plugins')
-rw-r--r--plugins/exec.lua19
1 files changed, 12 insertions, 7 deletions
diff --git a/plugins/exec.lua b/plugins/exec.lua
index e3decfd..fe87afc 100644
--- a/plugins/exec.lua
+++ b/plugins/exec.lua
@@ -10,13 +10,18 @@ local function exec(cmd, keep_newline)
end
+local function shell_quote(str)
+ return "'" .. str:gsub("'", "'\\''") .. "'"
+end
+
+
+local printfb_sub = {
+ ["\\"] = "\\\\",
+ ["\0"] = "\\0000",
+ ["'"] = "'\\''",
+}
local function printfb_quote(str)
- local sub = {
- ["\\"] = "\\\\",
- [string.char(0)] = "\\0000",
- ["'"] = "'\\''",
- }
- return "'" .. str:gsub(".", sub) .. "'"
+ return "'" .. str:gsub(".", printfb_sub) .. "'"
end
@@ -31,7 +36,7 @@ command.add("core.docview", {
core.command_view:enter("Replace With Result Of Command", function(cmd)
core.active_view.doc:replace(function(str)
return exec(
- "printf %b " .. printfb_quote(str:gsub("%\n$", "") .. "\n") .. " | " .. cmd,
+ "printf %b " .. printfb_quote(str:gsub("%\n$", "") .. "\n") .. " | eval '' " .. shell_quote(cmd),
str:find("%\n$")
)
end)