diff options
author | demotulatingswan <demotulatingswan@users.noreply.github.com> | 2020-06-09 22:58:49 +0200 |
---|---|---|
committer | demotulatingswan <demotulatingswan@users.noreply.github.com> | 2020-06-09 23:00:30 +0200 |
commit | af453b561606c2718d4d2d9ff7d4450c26892162 (patch) | |
tree | b0ab0fe6791fc6b1db8f7783c616f83347e52495 | |
parent | 0e8605da5c9ad371eb1f96e22f821d8c29a026e2 (diff) | |
download | lite-xl-plugins-af453b561606c2718d4d2d9ff7d4450c26892162.tar.gz lite-xl-plugins-af453b561606c2718d4d2d9ff7d4450c26892162.zip |
Fixed executing multiple commands in one go with exec:replace
-rw-r--r-- | plugins/exec.lua | 19 |
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) |