Skip to content

Instantly share code, notes, and snippets.

@paneru-rajan
Last active February 2, 2022 08:00
Show Gist options
  • Save paneru-rajan/4b170030ae8049128ddfb1408906953e to your computer and use it in GitHub Desktop.
Save paneru-rajan/4b170030ae8049128ddfb1408906953e to your computer and use it in GitHub Desktop.
[One Instance Gnome Terminal] #gnome-terminal #terminal

Force Only one instance of Gnome Terminal

I use tmux and I prefer only one instance of gnome-terminal open all the time. With the following script I achieve:

  1. Open a new terminal if there is no any terminal opened
  2. If terminal is already opened it will bring that terminal to the active workspace and focuses it
  3. If you execute script sitting on the active terminal, it minimizes the terminal

Steps:

  1. 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'
  1. Create a "Keyboard Shortcuts" with command as zsh -i -c "my-terminal", Set key Shortcuts per you interest

Note:

I am using zsh on ubuntu 20.04. I have xdotool installed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment