aboutsummaryrefslogtreecommitdiff
path: root/data/plugins/exec.lua
blob: a11ac9065aab72d9b38449c0ff1eba0b6e8eb72b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
local core = require "core"
local command = require "core.command"


local function exec(cmd)
  local fp = io.popen(cmd, "r")
  local res = fp:read("*a")
  fp:close()
  return res:gsub("%\n$", "")
end


command.add("core.docview", {
  ["exec:insert"] = function()
    core.command_view:enter("Insert Result Of Command", function(cmd)
      core.active_view.doc:text_input(exec(cmd))
    end)
  end,

  ["exec:replace"] = function()
    core.command_view:enter("Replace With Result Of Command", function(cmd)
      core.active_view.doc:replace(function(str)
        return exec(string.format("echo %q | %s", str, cmd))
      end)
    end)
  end,
})