Skip to content

Instantly share code, notes, and snippets.

@h4tr3d
Created November 28, 2024 04:16
Show Gist options
  • Save h4tr3d/52a164b0e4cb51abab85ffcd32609035 to your computer and use it in GitHub Desktop.
Save h4tr3d/52a164b0e4cb51abab85ffcd32609035 to your computer and use it in GitHub Desktop.
[Qt Creator] Helper script to open file in the current instance editor from the embedded terminal
#!/usr/bin/env bash
# TODO: check me
#QTC_EXE=${QTC_EXE:-qtcreator-master}
QTC_PTREE_DEBUG=${QTC_PTREE_DEBUG:-no}
get_ppid()
{
local pid=$1
ps -o ppid= -p $pid
}
get_cmd()
{
local pid=$1
ps -o cmd= -p $pid
}
get_comm()
{
local pid=$1
ps -o comm= -p $pid
}
ptree_debug()
{
local pid=$1
if [ "$QTC_PTREE_DEBUG" = "yes" ]; then
ps --no-headers s -p $pid
fi
}
# Scan process tree to find Qt Creator parent
pid=$PPID
qtc_pid=
while [ $pid -ne 1 ];
do
ptree_debug $pid
comm=$(get_comm $pid)
if [ "$comm" == "qtcreator" ]; then
qtc_pid=$pid
break;
fi
pid=$(get_ppid $pid)
done
if [ -z "$qtc_pid" ]; then
ptree_debug $pid
echo "Qt Creator parent was not found. Exit."
exit 0
fi
if [ -z "$QTC_EXE" ]; then
QTC_EXE=$(get_cmd $pid)
fi
# call existing parent
${QTC_EXE} -pid $pid "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment