Skip to content

Instantly share code, notes, and snippets.

@raidzero
Created March 20, 2015 17:29
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 raidzero/4fcd8a8f6da9971e482c to your computer and use it in GitHub Desktop.
Save raidzero/4fcd8a8f6da9971e482c to your computer and use it in GitHub Desktop.
Launch a new terminal or just find one and bring it to the foreground - meant for a keyboard shortcut or WM menu option
#!/bin/sh
HOSTNAME=`hostname`
# command to launch terminal
TERM_CMD="xfce4-terminal"
# what my terminal window name will always start with
NAME_PREFIX="#!"
# the name of the current terminal window - if more than one just guess and use the first
CURRENT_NAME=`wmctrl -l | grep "$NAME_PREFIX" | sed 's/^.*'"$HOSTNAME"' //' | head -n 1`
if [ -z "$CURRENT_NAME" ]; then
# not running, launch
$TERM_CMD &
else
# bring to foreground
wmctrl -a "$CURRENT_NAME"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment