Skip to content

Instantly share code, notes, and snippets.

@kuba-orlik
Created April 9, 2017 18:30
Show Gist options
  • Save kuba-orlik/ba800c691ee6cbf099504295b041b8dd to your computer and use it in GitHub Desktop.
Save kuba-orlik/ba800c691ee6cbf099504295b041b8dd to your computer and use it in GitHub Desktop.
Windows+number shortcuts for Linux
#!/bin/bash
# Usage:
# Put it somewhere where PATH points to and make it executable. Then:
# raisewindow.sh <executable name>
# Example:
# bind `<Windows (Super, Meta)> + 1` to `raisewindow.sh firefox`
# it will raise the firefox window if it's already open and launch firefox if it isn't
CMD=$1
if [ -n "$2" ]; then
CLASS=$2
else
CLASS=$CMD
fi
AMOUNT=`xdotool search --class $CLASS | xargs -L 1 -Iid bash -c 'echo id \`xwinfo -s id\`' | grep -v "N/A" | wc -l`
if [ $AMOUNT == 0 ]; then
notify-send "Starting $CLASS..." -i "$CLASS"
$CMD
fi;
xdotool search --class $CLASS | xargs -L 1 -Iid bash -c 'echo id `xwinfo -s id`' | grep -v -E "N/A|modal" | awk '{print $1}' | head -n 1 | xargs -Iid xdotool windowactivate id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment