Expose XWarpPointer to lua as rootwin:warp_pointer, for region_do_warp_alt
[notion.git] / contrib / scripts / exec_show.lua
blobe8b68f80a59da6f318051cdddf47cd8f70777afa
1 -- Authors: Sadrul Habib Chowdhury <imadil@gmail.com>
2 -- License: Public domain
3 -- Last Changed: Unknown
4 --
5 -- exec_show.lua: executes a command and displays the result
6 --
7 -- this script is meant to be used when the output for the command
8 -- doesn't have more than a screenful of lines (approx 30-35 lines).
9 -- eg. tail, head, grep, ps ... etc.
10 --
11 -- CAUTION
12 -- DO NOT use this to execute something like xterm, vi or anything
13 -- similar (use the given key-bindings like MOD2..F2/F3/F4/F5 for those).
15 -- do let me know if this doesn't work for someone.
17 -- Author
18 -- Sadrul Habib Chowdhury (Adil)
19 -- imadil at gmail dot com
21 function show_result(mp, msg)
22 mod_query.message(mp, msg)
23 end
25 function my_exec_handler(mp, cmd)
26 -- not defer-ing was causing some probs
27 ioncore.defer(
28 function ()
29 local f = io.popen(cmd, 'r')
30 if not f then
31 show_result(mp, 'error executing command: ' .. cmd)
32 return
33 end
35 local s = f:read('*a')
36 if s then
37 show_result(mp, s)
38 else
39 show_result(mp, 'no output')
40 end
41 f:close() -- remove this, and watch your life get ruined (thanx Tuomo)
42 end
45 end
47 function exec_and_show(mplex)
48 mod_query.query(mplex, TR("Exec and display:"), nil, my_exec_handler,
49 mod_query.exec_completor,
50 "execdisplay")
51 end
53 defbindings("WMPlex", {
54 bdoc("Execute a command and show the result."),
55 kpress(MOD1.."F4", "exec_and_show(_)"), -- change the binding to your liking