Skip to content

Instantly share code, notes, and snippets.

@wizpig64
Last active August 29, 2015 14:14
Show Gist options
  • Save wizpig64/19e613046efb9d3e2731 to your computer and use it in GitHub Desktop.
Save wizpig64/19e613046efb9d3e2731 to your computer and use it in GitHub Desktop.
X desktop: switch to or open new process
#!/bin/bash
#searches for $COMMAND in ps. if its found, switch to it using wmctrl, else start a new one.
#if any arguments are made ($@), $COMMAND will be run with them even if it's already running.
#tip: bind this to a spare mouse button with xbindkeys
#tip: save this as /usr/local/bin/terminator to override the command in /usr/bin using $PATH ordering.
#requires wmctrl. currently set up for terminator but could be used for any process.
COMMAND="/usr/bin/python /usr/bin/[t]erminator"
PID=`ps aux | grep "$COMMAND" | awk '{print $2}' | head -1`
if [ -z $PID ] || [ ! -z "$@" ]
then
$COMMAND $@
else
wmctrl -ia $(wmctrl -lp | awk -vpid=$PID '$3==pid {print $1; exit}')
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment