Skip to content

Instantly share code, notes, and snippets.

@vnprc
Last active December 24, 2022 14:51
Show Gist options
  • Save vnprc/5ab086ba4a6772503bf9 to your computer and use it in GitHub Desktop.
Save vnprc/5ab086ba4a6772503bf9 to your computer and use it in GitHub Desktop.
Hide, show, open terminal
#!/bin/bash
pids="$(pidof gnome-terminal-server)"
if [ -z "$pids" ]
then
gnome-terminal
else
focus_window_pid="$(xdotool getwindowfocus getwindowpid)"
if [[ $pids == *"$focus_window_pid"* ]]
then
xdotool getactivewindow windowminimize
else
wmctrl -lp | while read identity desktop_number PID window_title; do
if [[ $pids == *"$PID"* ]]; then
wmctrl -ia $identity
fi
done
fi
fi
@vnprc
Copy link
Author

vnprc commented Apr 2, 2015

I bound this shell script to a keyboard shortcut on my Ubuntu desktop. It makes for extremely quick access to the gnome terminal.

If a terminal window does not have focus, the script will move all terminals to the front and give one of them focus. If a terminal window does have focus, it will minimize that window. If no terminals are open, the script will open a new terminal.

Unfortunately, you need to install both xdotool and wmctrl because neither is fully featured enough to accomplish everything this script does.

sudo apt-get update
sudo apt-get install xdotool
sudo apt-get install wmctrl

@vnprc
Copy link
Author

vnprc commented Dec 24, 2022

This broke when I upgraded to Ubuntu 24. Switching back to Xorg from Wayland fixes it, though. https://beebom.com/how-switch-between-wayland-xorg-ubuntu/

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