4

I have a keyboard shortcut that is mapped to running the command gnome-terminal (I'm on Fedora 27).

I wish that this key, would open a new terminal if no terminal is open, but open a new tab on the existing terminal window if a terminal window is already open.

What would be the command to do that?

4 Answers4

0

I'm not sure entirely for Fedora but on CentOS the command to open a new tabbed terminal window is Ctrl+Shift+t when the terminal window is selected! as for opening a new window, you will have to bind that as you have done!

jamalm
  • 199
  • 4
  • 14
  • 1
    I am looking for a shell command that will start a terimnal if no terminals are open, and if there are it will open a new tab on the existing terminal. It should be a command not a keyboard stroke – bluesummers Nov 30 '17 at 10:03
  • oh you will want to write a small bash script to do that for you and then bind that to a key of your choice. I am unsure of how you will go about that, i guess capturing mouse events to see if you have the terminal selected and if so, create new tab, else just open a window. it seems like a lot of work for such a small task – jamalm Nov 30 '17 at 11:53
0

You'll need a way to detect a running terminal and send keys to that window. There are several of them. I'd suggest you xdotool ( sudo dnf install xdotool for Fedora )

#!/bin/sh
EW=$(xdotool search --onlyvisible --classname Gnome-terminal|head -1)

if [[ -z  $EW ]]
then
 gnome-terminal &
else
 xdotool windowactivate --sync  $EW
 xdotool key --clearmodifiers ctrl+shift+t
fi

Put this code above in, say, ~/bin/gterm file then make chmod 0755 ~/bin/gterm

Afterwards gterm command is ready. Furthermore you can bind it to a shortcut.

Tagwint
  • 2,480
  • When I try to do that, I get the following error not found XGetWindowProperty[_NET_WM_DESKTOP] failed (code=1) (trying it on Ubuntu instead of Fedora) – bluesummers Nov 30 '17 at 21:29
0
osascript -e 'tell app "Terminal"
    do script "echo hello"
end tell'

This opens a new terminal and executes the command "echo hello" inside it.

Source

Jeremy
  • 101
0

I was thinking as you said in the comment

gnome-terminal

enter image description here

If you run the code it will open another terminal from a existing terminal