Last active
November 7, 2021 14:45
-
-
Save shaybensasson/7392e2a31ec7a7284056c0837af368ad to your computer and use it in GitHub Desktop.
Opening a new tab in an existing GNOME terminal window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# from here: https://planet.jboss.org/post/opening_a_new_tab_in_an_existing_gnome_terminal_window | |
# Path: /usr/local/bin/gnome-terminal | |
if [ "x$*" != "x" ]; then # any args? | |
/usr/bin/gnome-terminal "$@" | |
exit 0 | |
fi | |
# first, inspect the current window | |
WID=`xdotool getwindowfocus` | |
#echo "~~~~$WID~~~~" | |
if [ "x$WID" == "x" ]; then #no window found | |
echo '"getwindowfocus" did not find any window.' | |
/usr/bin/gnome-terminal | |
exit 0 | |
fi | |
LIST=`xdotool search --onlyvisible --class "gnome-terminal"` | |
EXISTS=`echo $LIST | grep -w $WID` | |
if [ "x$EXISTS" != "x" ]; then #current window is terminal | |
echo 'current window is a terminal' | |
# xdotool windowfocus $WID | |
# xdotool windowraise $WID | |
# #xwininfo -id $WID #window info | |
# sleep 0.5 #this is essential so window would be activated, and only then we can send keys | |
# xdotool key ctrl+shift+t #start a new terminal tab | |
#we just start a new process (we're already in a terminal, so the user can create a new tab easily) | |
/usr/bin/gnome-terminal | |
exit 0 | |
fi | |
echo 'Current window is not gnome-terminal.' | |
WID=`xdotool search --onlyvisible --class "gnome-terminal" | tail -1` | |
if [ "x$WID" == "x" ]; then | |
echo 'No open terminal; Running brand new process.' | |
/usr/bin/gnome-terminal | |
exit 0 | |
fi | |
echo 'Found a running console.' | |
#xdotool search --onlyvisible --class "gnome-terminal" | |
#echo . | |
#echo "~~~~$WID~~~~" | |
#wmctrl -ia $WID | |
xdotool windowactivate $WID | |
xdotool windowraise $WID | |
xdotool windowfocus $WID | |
sleep .5 | |
#xwininfo -id $WID #window info | |
xdotool key ctrl+shift+t #start a new terminal tab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment