aboutsummaryrefslogtreecommitdiff
path: root/data/plugins/exec.lua
diff options
context:
space:
mode:
authorrxi <rxi@users.noreply.github.com>2019-12-28 11:16:32 +0000
committerrxi <rxi@users.noreply.github.com>2019-12-28 11:17:56 +0000
commitd8c4bfa6bad7153486fd68f8c9368dc3bb458ce5 (patch)
tree296b4e8d51b4cf60d7a6f809f2886b79cdb29981 /data/plugins/exec.lua
downloadpragtical-d8c4bfa6bad7153486fd68f8c9368dc3bb458ce5.tar.gz
pragtical-d8c4bfa6bad7153486fd68f8c9368dc3bb458ce5.zip
Initial commit
Diffstat (limited to 'data/plugins/exec.lua')
-rw-r--r--data/plugins/exec.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/data/plugins/exec.lua b/data/plugins/exec.lua
new file mode 100644
index 00000000..a11ac906
--- /dev/null
+++ b/data/plugins/exec.lua
@@ -0,0 +1,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,
+})