NOTE: This macro requires the newer xfgrep version 1.10 which can be found here.
Code: Select all
--
-- Name: Workspace Search Example
--
-- Author: Jussi Jumppanen
--
-- Language: Lua Macro
--
-- Description: This simple Lua macro will search the current workspace
-- for the user supplied input string.
--
function build_response_file()
-- get then names of all the projects
local names = projects(",")
local file_name = macro_tag("$BackupDir") .. "response_file.txt"
local fh = assert(io.open(file_name, "w"))
-- get all the files in each all the projects
for name in string.gmatch(names, "[^,]+") do
files = project_files(name, 1, "\\n")
-- write the list of files to the input response file
fh:write(files)
fh:write("\n")
end
fh:close()
return file_name
end
function key_macro()
is_open = is_workspace_open()
if (is_open == 1) then
-- default to the current word or highlighted text
local nill = macro_tag("$WEX")
-- ask for a user for a command line
local pattern = user_input("Find Text:", nill)
if string.len(pattern) > 0 then
-- get then names of all files in all the projects
local file_name = build_response_file()
-- check the pattern for spaces
if (pattern:find(' ') ~= nill) then
pattern = "\"" .. pattern .. "\""
end
-- check the response file name for spaces
if (file_name:find(' ') ~= nill) then
file_name = "\"" .. file_name .. "\""
end
-- create the cmd string
local cmd = "xfgrep.exe -f -n -i -r " .. pattern .. " " .. file_name
-- setup command control falgs (see the Zeus Macro help for details)
local flags = 2+4+16+32
-- run grep command using the response file as an input
system(cmd, "", flags)
else
message("Operation cancelled by user.")
end
else
message("Now workspace currently open")
end
end
key_macro() -- run the macro