#! /usr/bin/env lua
-- echo ls cd

sel=geany.selection()
-- geany.launch ('xfce4-terminal', '--hold', '-e', 'man '..sel)

-- get geany bash pid
local handle = io.popen([[bash -c 'pid=$(pgrep geany) && pstree -p $pid | grep -oP "(?<=bash().*?(?=))" | head -n 1']])
local geany_bash_pid = handle:read("*a")
handle:close()
geany.status("Geany bash pid is: "..geany_bash_pid)

-- get pts pid which = geany_bash_pid
for i=0,10 do

local handle = io.popen([[bash -c 'ps -t pts/]]..i..[[ | sed -n "2p" | grep -oP "(?<= ).*?(?=pts/)" | sed "s/ //g"']])
local pts_pid = handle:read("*a")
handle:close()
geany.status("PTS pid is: "..pts_pid)

if string.find(pts_pid, geany_bash_pid) then
geany_bash_pts = i
geany.status("FOUND IT !: "..geany_bash_pts)
break
end
end

-- send geany selection with man command to geany's internal terminal by using open-source utility ttyecho
-- ttyecho stackoverflow info: https://stackoverflow.com/questions/24725051/execute-a-command-in-another-terminal-via-dev-pts
-- ttyecho original article: http://www.humbug.in/2010/utility-to-send-commands-or-data-to-other-terminals-ttypts/
-- ttyecho original article (web.archive): https://web.archive.org/web/20240324125143/http://www.humbug.in/2010/utility-to-send-commands-or-data-to-other-terminals-ttypts/
-- ttyecho original sources: https://github.com/osospeed/ttyecho
-- ttyecho fork sources: https://github.com/andreabenini/ttyEcho
-- ttyecho executable need to be modified after building from sources for execution without root (attention! - check sources!)
-- modification: sudo chown root:root ttyecho && sudo chmod u+s ttyecho
local handle = io.popen([[bash -c '~/.config/geany/plugins/helpers/ttyecho -n /dev/pts/]]..geany_bash_pts..[[ man\ ]]..sel..[[']])
handle:close()


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <geany/geany-plugins/issues/1373/2352128597@github.com>