Is it possible to close a terminal tab from the command line by targeting its title?
Not exactly what I was looking for, but found a roundabout way to accomplish what I needed, in case this helps someone else:
The terminal tab in my case is a node server that outputs a log while it's running, so it stays open while the process is live. At least on Ubuntu, you can set the window to close itself based on the terminal profile preferences:
Which means I can simply kill the process and the tab will close. To accomplish this, I added a command that I prepend to the scripts I use when switching projects:
ps -aux | grep "commandnamehere" | grep -v "grep" | awk '{print $2}' | xargs kill
Alternatively, you can kill the process occupying a specific port, which also worked in my case:
kill $(lsof -t -i:7777)
Edit:
In case you want to just slap the kill process before some other scripts like I did, you might also want a function that checks to see if there is a process to kill:
killpid() {
PID=`ps -aux | grep "commandnamehere" | grep -v "grep" | awk '{print $2}'`;
if [ ! -z "$PID" ]
then
echo "killing commandnamehere - $PID";
echo $PID | xargs kill;
fi
}