Skip to content

Instantly share code, notes, and snippets.

@mmodrow
Last active March 22, 2019 08:42
Show Gist options
  • Save mmodrow/911bd9bd6f15d7f70006dd362d65372b to your computer and use it in GitHub Desktop.
Save mmodrow/911bd9bd6f15d7f70006dd362d65372b to your computer and use it in GitHub Desktop.
Start a GUI application from the Linux terminal without blocking the terminal.
#!/bin/bash
force=0
for arg in "$@"
do
if [[ "$arg" = "-h" || "$arg" = "--help" ]]
then
echo "Just add program starting commands as parameters as you please. They will be started in order."
echo "Add '-f' at any point to apply force mode to all following programs."
echo "Add '-F' at any point to remove force mode to all following programs."
continue
fi
if [ "$arg" = "-f" ]
then
let force=1
echo "Applying force."
continue
fi
if [ "$arg" = "-F" ]
then
let force=0
echo "Removing force."
continue
fi
alreadyRunning=`ps -aux | grep "$arg" | egrep -v "grep|start" | xargs`
if [[ "$alreadyRunning" = "" || "$force" = "1" ]]
then
echo "starting $arg"
($arg &> /dev/null &)
else
echo "$arg is already running"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment