I desire that when I log into my gnome workstation that a gnome-terminal pops up, with several tabs already opened and commands already running in them.
I read the man page, and tried to accomplish this with a simple script:
#!/bin/bash
gnome-terminal --tab -t htop -- htop
gnome-terminal --tab -t XPRA -e 'xa'
gnome-terminal --tab -t hosta -- autossh -M $RANDOM a
gnome-terminal --tab -t hostb -- autossh -M $RANDOM b
gnome-terminal --tab -t hostc -- autossh -M $RANDOM c
gnome-terminal --tab -t MTR -- mtr 1.1.1.1
I ran that script and up popped all the tabs I wanted. Neat. So then I put it in an autostart file:
$ cat .config/autostart/StartTerms.desktop
[Desktop Entry]
Encoding=UTF-8
Exec=/home/myuser/bin/StartTerms
Name=StartTerms
Comment=Start my terminal sessions (autossh to various servers)
Terminal=false
OnlyShowIn=GNOME
Type=Application
StartupNotify=false
X-GNOME-Autostart-enabled=true
Raise your hand if you know what I was doing wrong…
I rebooted, logged in, and boom, I get pummeled with 6 individual windows, NOT 6 tabs in one window.
I thought: "Perhaps the second and subsequent gnome-temrminal --tab commans are being invoked before the first one has caused its window to display, so the subsequent ones think they’re all first and open their own windows.
I also found out that if autossh runs before the wifi is connected, then it exits.
So I found out that wmctrl can list all the visible windows. I figured that during the time between the gnome-terminal command being invoked and the time it’s ready to accept new --tabs from another command, its window would’t be in that list, so put this clever bit together right after the first one runs and before any subsequent invocations:
lock="/tmp/waitformoreterms"
touch "${lock}"
while [[ -f "${lock}" ]]
do
wmctrl -lp | \
while read hex zero pid foo
do
if grep -q 'gnome-terminal-server' '/proc/'"${pid}"'/cmdline'
then
echo "Process ${pid} is an already-visible terminal. save to proceed..."
rm "${lock}"
break 2
fi
done
if [[ -f "${lock}" ]]
then
sleep 1
fi
done
AAAAAND fail. IT still bombs me with multiple seperate windows on login. What on earth am I doing wrong? How can I get multiple taps to come up with specific commands in them when I log into gnome?