-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell-strip-wrapper.lua
More file actions
73 lines (63 loc) · 2.25 KB
/
shell-strip-wrapper.lua
File metadata and controls
73 lines (63 loc) · 2.25 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function OnClear()
scite.StripShow("")
end
function StripDlg(args)
local t = {}
for k, v in string.gmatch(args, "(%w+)=([^ ]+)") do t[k] = v end
if t["func"] then
StripFunc = t["func"]
if not t["dlg"] then t["dlg"] = "'" .. t["func"] .. "'[](&OK)(&Cancel)" end
_, w = t["dlg"]:gsub("['{}%(%)%[%]]", "")
scite.StripShow(t["dlg"]:gsub('\\n', '\n'))
else
print("Invalid call")
end
if StripFunc == "Shell" or StripFunc == "Python" then
local history = io.open(props["SciteUserHome"] .. "/SciTE-" .. StripFunc .. ".hist", "r")
if history then
h = history:read("*a")
history:close()
else
h = ""
end
scite.StripSetList(1, h)
end
end
function OnStrip(control, change)
if change == 1 then
local val = {}
for i = 0, w/2-1 do
if scite.StripValue(i) ~= "" then table.insert(val, scite.StripValue(i)) end
end
StripExec(val[1], val[2], control)
end
end
function StripExec(val1, val2, c)
if editor:GetSelText() == "" then editor:SelectAll() end
if StripFunc == "Shell" or StripFunc == "Python" then
-- execute:
if val1 ~= "" and c == 2 then
cmd = val1:gsub('\\', '\\\\'):gsub('"', '\\"')
if StripFunc == "Python" then
run = 'python -c "import sys,re,sets;scite=sys.stdin.read()\n' .. cmd
else
run = 'sh -c "' .. cmd:gsub('$$', '\\$$')
end
local out = io.popen(run .. '" 2>&1 << cvJZ1hqModtnAqBG\n' .. editor:GetSelText() .. '\ncvJZ1hqModtnAqBG')
print(out:read("*a"))
out:close()
end
-- history:
if h ~= "" and val1 ~= "" and c > 2 then
local f = props["SciteUserHome"] .. "/SciTE-" .. StripFunc .. ".hist"
local tt = {}
for line in io.lines(f) do
if line ~= val1 then table.insert(tt, line) end
end
if c == 3 then table.insert(tt, val1) end
local history = io.open(f, "w")
for i, j in pairs(tt) do history:write(j .. '\n') end
history:close()
end
end
end