diff options
author | rxi <rxi@users.noreply.github.com> | 2020-06-19 11:54:18 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-19 11:54:18 +0100 |
commit | cbcccb49651f0e6403314f9838fd0a8f9f4fd77e (patch) | |
tree | 7e5b0e05cd3b1b9f160b6d5d16ed1733a847416a /plugins | |
parent | 57d48b55ed23d477b73110fdea8e98769a98a451 (diff) | |
parent | af453b561606c2718d4d2d9ff7d4450c26892162 (diff) | |
download | lite-xl-plugins-cbcccb49651f0e6403314f9838fd0a8f9f4fd77e.tar.gz lite-xl-plugins-cbcccb49651f0e6403314f9838fd0a8f9f4fd77e.zip |
Merge pull request #55 from demotulatingswan/master
Fixed executing multiple commands in one go with exec:replace
Diffstat (limited to 'plugins')
-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) |