run-once 406 B

123456789101112131415161718
  1. #!/bin/sh
  2. #### HELP MESSAGE ##############################################
  3. hlp='Usage: run-once PROGRAM [ARGS ...]
  4. Start PROGRAM if it is not already running.'
  5. if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
  6. echo "$hlp"
  7. exit 0
  8. fi
  9. ################################################################
  10. if [[ -z $(pgrep -U $(id --user) "^$1$") ]]; then
  11. "$@"
  12. else
  13. echo "$1 is already running"
  14. fi