Let's try to use a temporary file, other ways are not very clear to me yet. ```lua local aTemplate = 'sort -f "$TMPFILE"'
local sTmpFile, sTmpStr, bFullText, sCommand
local aFileInfo = geany.fileinfo() if aFileInfo.ext == nil then sTmpFile = os.tmpname() .. ".txt" else sTmpFile = os.tmpname() .. aFileInfo.ext end
local iStart, iStop = geany.select() local h = io.open(sTmpFile, "wb") if h == nil then geany.message("Fail 1.") return end sTmpStr = geany.selection() if sTmpStr == nil then geany.message("Fail 2.") return elseif sTmpStr == "" then sTmpStr = geany.text() bFullText = true end h:write(sTmpStr) h:close()
sCommand = string.gsub(sTemplate, "%$TMPFILE", sTmpFile) h = io.popen(sCommand, "r") if h == nil then geany.message("Fail 3.") return end sTmpStr = h:read("*a") h:close() sTmpStr = string.gsub(sTmpStr, "\r*[\r\n]$", "") if bFullText == true then geany.text(sTmpStr) geany.select(iStart) else geany.selection(sTmpStr) geany.select(iStart, iStop) end geany.message("Done.") ``` See the template in the value of the `sTemplate` variable (first line). If you want to use, for example, `grep`, then try ```lua local sTemplate = 'cat "$TMPFILE" | grep "some text"' ``` Probably, in this case it is better to use the `geany.choose` function instead of separate scripts.
Try with and without selection.