Skip to content

Instantly share code, notes, and snippets.

@rolandcrosby
Created April 25, 2020 02:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rolandcrosby/dfb45bcdd7bda9af84a34463bf198615 to your computer and use it in GitHub Desktop.
Save rolandcrosby/dfb45bcdd7bda9af84a34463bf198615 to your computer and use it in GitHub Desktop.
switch to gnome-terminal if it's open, otherwise launch a new one
#!/bin/bash
read -r win_found <<<$(wmctrl -l -p | awk '{print $1,$3}' | while read -r wins; do ps -o command= -p "${wins/0x* /}" | grep -q gnome-terminal && echo "${wins/ */}" && break; done)
if [ -z "$win_found" ]; then
gnome-terminal
else
wmctrl -i -a $win_found
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment