Skip to content

Instantly share code, notes, and snippets.

@codepuncher
Created July 19, 2017 11:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codepuncher/806cabf9c72263fbd5addd50ade39ad8 to your computer and use it in GitHub Desktop.
Save codepuncher/806cabf9c72263fbd5addd50ade39ad8 to your computer and use it in GitHub Desktop.
Quickwin - Focus active window or open program
#!/usr/bin/env bash
# Focus window from 1st argument or
# executes command from 2nd argument
wmctrl -ia $(wmctrl -l | grep -i ${1} | awk '{print $1}') || ${2} &
# Example usage:
# from cli
./quickwin 'user@hostname:' 'gnome-terminal --hide-menubar' # Tries to focus window with title 'user@hostname:' or run gnome-terminal
./quickwin 'chrome' 'google-chrome'
# keyboard shortcut usage
bash -c "~/.local/bin/quickwin 'user@hostname:' 'gnome-terminal --hide-menubar'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment