Last active
August 29, 2015 14:14
-
-
Save wizpig64/19e613046efb9d3e2731 to your computer and use it in GitHub Desktop.
X desktop: switch to or open new process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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