all repos — zenUtils @ main

misc utilities for computing zen

sirius.sh (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh

# fetch your mail at regular intervals
# Derek Stevens <nilix@nilfm.cc>
# MIT License

inbox=~/lib/mail/zoho/INBOX
tarosock=~/lib/taro/taro.sock

if [ "$1" = "-s" ]; then
  oldnew=$(\ls -1 ${inbox}/new | wc -l)
  
  dots="   "
  mbsync -a &
  
  while pgrep mbsync; do
    case $dots in
      "...")
        dots=" ..";;
      " ..")
        dots="  .";;
      "  .")
        dots="   ";;
      "   ")
        dots=".  ";;
      ".  ")
        dots=".. ";;
      ".. ")
        dots="...";;
    esac
    notify-send -c mail 'mail' "[syncing${dots}]"
    sleep 1
  done
  newnew=$(\ls -1 ${inbox}/new | wc -l)

  if [ ${newnew} -gt ${oldnew} ]; then
    notify-send -c mail 'new mail' "[${newnew}]"
    if [ -S ${tarosock} ]; then
      printf "0" | socat UNIX-CONNECT:${tarosock} -
      echo "pushed to socket"
    fi
  else
    notify-send -c mail 'mail' "[sync complete]"
  fi

else
  oldnew=0
  while true; do
    mbsync -a
    newnew=$(\ls -1 ${inbox}/new | wc -l)

    if [ ${newnew} -gt ${oldnew} ]; then
      notify-send -c mail 'new mail' "[${newnew}]"
      if [ -S ${tarosock} ]; then
        printf "0" | socat UNIX-CONNECT:${tarosock} -
        echo "pushed to socket"
      fi
    fi
    oldnew=${newnew}
    sleep 5m
    echo "slept 5m"
  done
fi