doing 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env bash
  2. # SYNOPSIS
  3. # poor-man's daemon: nohup doing & &> /dev/null
  4. # log entry: doing [what you're doing]
  5. # ------------------------------------------
  6. haz() {
  7. command -v "$1" > /dev/null 2>&1
  8. }
  9. logfile="$HOME/.doing"
  10. if ! haz notify-send || ! haz xdotool || ! haz xwininfo; then
  11. printf "[$(tput setaf 1)ERROR$(tput sgr0)] Unable to find all dependencies"
  12. exit 1;
  13. fi
  14. # logging daemon
  15. if (( $# == 0 )); then
  16. while ((1)); do
  17. _prog=$(cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm)
  18. _wintitle=$(xwininfo -root -children | grep $(printf '%x' $(xdotool getwindowfocus)) | grep -oEi '"[^"]+"' | head -1 | tr -d '"')
  19. _weather=$(weathermajig boulder)
  20. _date=$(date +'%Y-%m-%d %H:%M:%S')
  21. # date/time | weather | program | window title
  22. echo "$_date | $_weather | $_prog | $_wintitle" >> "$logfile"
  23. unset _prog _wintitle _weather _date
  24. sleep 1800;
  25. done;
  26. exit 0;
  27. fi
  28. if [[ $1 == "--show" ]]; then
  29. cat $logfile | column -s '|' -t
  30. exit 0
  31. fi
  32. if [[ $1 == "--debug" ]]; then
  33. while ((1)); do
  34. _prog=$(cat /proc/$(xdotool getwindowpid $(xdotool getwindowfocus))/comm)
  35. _wintitle=$(xwininfo -root -children | grep $(printf '%x' $(xdotool getwindowfocus)) | grep -oEi '"[^"]+"' | head -1 | tr -d '"')
  36. _weather=$(weathermajig boulder --short)
  37. _date=$(date +'%Y-%m-%d %H:%M:%S')
  38. # date/time | weather | program | window title
  39. echo "$_date | $_weather | $_prog | $_wintitle"
  40. unset _prog _wintitle _weather _date
  41. sleep 5
  42. done;
  43. exit 0
  44. fi