autostart.sh 771 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. # lauch these programs at autostart only once
  4. # add programs to this array
  5. programs=(dunst mpd redshift transmission-daemon sxhkd gxkb
  6. wallpaper-set-random.sh 'emacs --daemon')
  7. notify(){
  8. message="${1}: ${@:2}"
  9. notify-send "$message"
  10. echo "$message"
  11. }
  12. check_status(){
  13. base="${1%% *}" # command without flags
  14. if ! command -v "$base" 1>/dev/null; then
  15. notify "$base" "not installed"
  16. return 2 # for continue
  17. elif ! pgrep -f "$base" 1>/dev/null; then
  18. notify "$base" "starting"
  19. return 2 # for continue
  20. fi
  21. notify "$base" "already running"
  22. }
  23. for prog in "${programs[@]}"; do
  24. check_status "$prog" && continue
  25. $prog &>/dev/null &
  26. done