1 -- Authors: Sadrul Habib Chowdhury <imadil@gmail.com>
2 -- License: Public domain
3 -- Last Changed: Unknown
5 -- exec_show.lua: executes a command and displays the result
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.
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.
18 -- Sadrul Habib Chowdhury (Adil)
19 -- imadil at gmail dot com
21 function show_result(mp
, msg
)
22 mod_query
.message(mp
, msg
)
25 function my_exec_handler(mp
, cmd
)
26 -- not defer-ing was causing some probs
29 local f
= io
.popen(cmd
, 'r')
31 show_result(mp
, 'error executing command: ' .. cmd
)
35 local s
= f
:read('*a')
39 show_result(mp
, 'no output')
41 f
:close() -- remove this, and watch your life get ruined (thanx Tuomo)
47 function exec_and_show(mplex
)
48 mod_query
.query(mplex
, TR("Exec and display:"), nil, my_exec_handler
,
49 mod_query
.exec_completor
,
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