I use tmux and I prefer only one instance of gnome-terminal open all the time. With the following script I achieve:
- Open a new terminal if there is no any terminal opened
- If terminal is already opened it will bring that terminal to the active workspace and focuses it
- If you execute script sitting on the active terminal, it minimizes the terminal
- Adding following script to your
.bashrc
or.zshrc
file
my-terminal='actid=$(xdotool getactivewindow) ; terid=$(xdotool search --onlyvisible --class gnome-terminal) ; if ps aux | grep "[g]nome-terminal" > /dev/null; then if [[ "$actid" == "$terid" ]]; then xdotool windowminimize $terid; else xdotool set_desktop_for_window $terid $(xdotool get_desktop) && sleep .1 && xdotool windowactivate $terid; fi; else gnome-terminal --maximize; fi'
- Create a "Keyboard Shortcuts" with command as
zsh -i -c "my-terminal"
, Set key Shortcuts per you interest
I am using zsh on ubuntu 20.04. I have xdotool
installed as well.