Last active
December 24, 2022 14:51
-
-
Save vnprc/5ab086ba4a6772503bf9 to your computer and use it in GitHub Desktop.
Hide, show, open terminal
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 | |
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 |
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
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