You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
3.3 KiB
158 lines
3.3 KiB
3 years ago
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||
|
<!DOCTYPE muclient>
|
||
|
<!-- Saved on Saturday, July 31, 2021, 10:24 PM -->
|
||
|
<!-- MuClient version 5.07-pre -->
|
||
|
|
||
|
<!-- Plugin "Grep" generated by Plugin Wizard -->
|
||
|
|
||
|
<muclient>
|
||
|
<plugin
|
||
|
name="grep"
|
||
|
author="Naricain"
|
||
|
id="679991ab2cdc79c2743f37a8"
|
||
|
language="Lua"
|
||
|
purpose="Search for matching lines with a command's output"
|
||
|
save_state="y"
|
||
|
date_written="2021-07-31 22:24:07"
|
||
|
requires="5.00"
|
||
|
sequence="-5000"
|
||
|
version="1.0"
|
||
|
>
|
||
|
|
||
|
</plugin>
|
||
|
|
||
|
<aliases>
|
||
|
<alias
|
||
|
match="^(?<cmd>.+) \| grep (?<query>.+)$"
|
||
|
script="grep"
|
||
|
name="grep"
|
||
|
enabled="y"
|
||
|
regexp="y"
|
||
|
sequence="100"
|
||
|
ignore_case="y"
|
||
|
echo_alias="y"
|
||
|
send_to="12" />
|
||
|
<alias
|
||
|
match="^grep reload$"
|
||
|
script="reload"
|
||
|
name="reload"
|
||
|
enabled="y"
|
||
|
regexp="y"
|
||
|
sequence="100"
|
||
|
ignore_case="y"
|
||
|
send_to="12" />
|
||
|
</aliases>
|
||
|
<triggers>
|
||
|
<trigger
|
||
|
match="^GREP START: \{(?<query>.+)\}$"
|
||
|
script="grep_start"
|
||
|
name="grep_start"
|
||
|
enabled="y"
|
||
|
regexp="y"
|
||
|
sequence="1"
|
||
|
keep_evaluating="y"
|
||
|
omit_from_output="y"
|
||
|
send_to="12" />
|
||
|
|
||
|
<trigger
|
||
|
match="^.*$"
|
||
|
script="grep_match"
|
||
|
name="grep_match"
|
||
|
enabled="n"
|
||
|
regexp="y"
|
||
|
sequence="100"
|
||
|
keep_evaluating="y"
|
||
|
omit_from_output="y"
|
||
|
send_to="12" />
|
||
|
|
||
|
<trigger
|
||
|
match="^GREP END$"
|
||
|
script="grep_end"
|
||
|
name="grep_end"
|
||
|
enabled="y"
|
||
|
regexp="y"
|
||
|
sequence="1"
|
||
|
omit_from_output="y"
|
||
|
send_to="12" />
|
||
|
</triggers>
|
||
|
|
||
|
<script>
|
||
|
<![CDATA[
|
||
|
local current_grep_query
|
||
|
|
||
|
function reload()
|
||
|
InfoNote("Reloading ", "Grep")
|
||
|
Execute(GetAlphaOption("script_prefix") .. "DoAfterSpecial(1, \"ReloadPlugin('" .. GetPluginID() .. "')\", sendto.script)")
|
||
|
end
|
||
|
|
||
|
function generate_grep_query(query)
|
||
|
return rex.new(query, rex.flags().CASELESS)
|
||
|
end
|
||
|
|
||
|
function grep(name, line, wildcards)
|
||
|
local status = pcall(generate_grep_query, wildcards.query)
|
||
|
if status then
|
||
|
SendNoEcho("echo GREP START: {" .. wildcards.query .. "}")
|
||
|
SendNoEcho(wildcards.cmd)
|
||
|
SendNoEcho("echo GREP END")
|
||
|
else
|
||
|
InfoNote("Grep query ", wildcards.query, " is not a valid regular expression")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function grep_start(name, line, wildcards)
|
||
|
local status, query_regex = pcall(generate_grep_query, wildcards.query)
|
||
|
if status then
|
||
|
current_grep_query = query_regex
|
||
|
EnableTrigger("grep_match", true)
|
||
|
else
|
||
|
InfoNote("Grep query ", wildcards.query, " is not a valid regular expression")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function grep_match(name, line, wildcards, style)
|
||
|
-- print("line ", line)
|
||
|
if not current_grep_query then
|
||
|
InfoNote("Missing grep query")
|
||
|
EnableTrigger("grep_match", false)
|
||
|
return
|
||
|
end
|
||
|
|
||
|
if current_grep_query:match(line) then
|
||
|
for i, s in ipairs(style) do
|
||
|
NoteStyle(s.style)
|
||
|
ColourTell(RGBColourToName(s.textcolour), RGBColourToName(s.backcolour), s.text)
|
||
|
end
|
||
|
return Note("")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function grep_end()
|
||
|
current_grep_query = nil
|
||
|
EnableTrigger("grep_match", false)
|
||
|
end
|
||
|
|
||
|
local LOG_COLORS = {
|
||
|
INFO = "#A9A9A9",
|
||
|
INFO_HIGHLIGHT = "#4169E1",
|
||
|
}
|
||
|
|
||
|
function InfoNote(...)
|
||
|
log_with_alternating_note({"Grep: ",...}, LOG_COLORS.INFO_HIGHLIGHT, LOG_COLORS.INFO)
|
||
|
end
|
||
|
|
||
|
function log_with_alternating_note(messages, color1, color2, background)
|
||
|
if background == nil then
|
||
|
background = ""
|
||
|
end
|
||
|
for i, message in ipairs(messages) do
|
||
|
ColourTell(color1, background, message)
|
||
|
color1, color2 = color2, color1
|
||
|
end
|
||
|
Note("")
|
||
|
end
|
||
|
|
||
|
]]>
|
||
|
</script>
|
||
|
</muclient>
|