diff options
author | Yaroslav <contact@yaroslavps.com> | 2020-04-09 01:30:04 +0300 |
---|---|---|
committer | Yaroslav <contact@yaroslavps.com> | 2020-04-09 01:30:04 +0300 |
commit | d5c97e78d80177119421f9dade324b04f2b00126 (patch) | |
tree | 7a637bf2a8ea613f7480301434e778ad6d8b6f42 /dotfiles/.local | |
parent | 2a7d8cecace432898722b0d2c7a2543e1057cf74 (diff) | |
download | swayrice-d5c97e78d80177119421f9dade324b04f2b00126.tar.gz swayrice-d5c97e78d80177119421f9dade324b04f2b00126.zip |
mail scripts for aerc+mbsync; goodbye neomutt
Diffstat (limited to 'dotfiles/.local')
-rwxr-xr-x | dotfiles/.local/bin/barmailstatus | 14 | ||||
-rwxr-xr-x | dotfiles/.local/bin/mailsync | 43 | ||||
-rwxr-xr-x | dotfiles/.local/bin/newssync | 3 | ||||
-rwxr-xr-x | dotfiles/.local/bin/pacsync | 9 |
4 files changed, 66 insertions, 3 deletions
diff --git a/dotfiles/.local/bin/barmailstatus b/dotfiles/.local/bin/barmailstatus new file mode 100755 index 0000000..d40a73d --- /dev/null +++ b/dotfiles/.local/bin/barmailstatus @@ -0,0 +1,14 @@ +#!/bin/sh + +total=0 + +# Check all accounts/mailboxes for new mail. +for mailbox in "$HOME/.local/share/mail/"* +do + account="$(echo "$mailbox" | sed "s/.*\///")" + newcount=$(find "$HOME/.local/share/mail/$account/INBOX/new/" "$HOME/.local/share/mail/$account/Inbox/new/" "$HOME/.local/share/mail/$account/inbox/new/" -type f 2> /dev/null | wc -l) + total=$((total + newcount)) +done + +[ $total -gt 0 ] && echo "$total" + diff --git a/dotfiles/.local/bin/mailsync b/dotfiles/.local/bin/mailsync new file mode 100755 index 0000000..9da6270 --- /dev/null +++ b/dotfiles/.local/bin/mailsync @@ -0,0 +1,43 @@ +#!/bin/sh +# Sync mail and give notification if there is new mail. + +# Run only if user logged in (prevent cron errors) +w | grep "^$USER\W" >/dev/null || exit + +# Check several times before giving up, useful when just waking up from sleep +# since internet is usually not available right away +wget -q --tries=5 --timeout=20 --spider 1.1.1.1 > /dev/null || exit + +# Source the needed env variables so that it can function properly from cron +. ~/.cache/sessionenv + +thereis=0 + +# Run mbsync. You can feed this script different settings. +if [ $# -eq 0 ]; then + mbsync -a +else + mbsync "$@" +fi + +# Check all accounts/mailboxes for new mail. Notify if there is new content. +for mailbox in "$HOME/.local/share/mail/"* +do + account="$(echo "$mailbox" | sed "s/.*\///")" + newcount=$(find "$HOME/.local/share/mail/$account/INBOX/new/" "$HOME/.local/share/mail/$account/Inbox/new/" "$HOME/.local/share/mail/$account/inbox/new/" -type f -newer "$HOME/.cache/lastmailsync" 2> /dev/null | wc -l) + if [ "$newcount" -gt "0" ]; then + notify-send "📬 Email" "$newcount new mail(s) in \`$account\` mailbox." + thereis=1 + fi +done + +if [ $thereis = 1 ]; then + mpv "$HOME/.local/share/soundalerts/mail.mp3" > /dev/null + killall -42 waybar +fi + +notmuch new 2>/dev/null + +# Create a touch file that indicates the time of the last run of mailsync +touch "$HOME/.cache/lastmailsync" + diff --git a/dotfiles/.local/bin/newssync b/dotfiles/.local/bin/newssync index 607188d..ebe41e1 100755 --- a/dotfiles/.local/bin/newssync +++ b/dotfiles/.local/bin/newssync @@ -1,5 +1,8 @@ #!/bin/sh +# Run only if user logged in (prevent cron errors) +w | grep "^$USER\W" >/dev/null || exit + # Don't try to update feed if newsboat is already running if pidof newsboat; then exit diff --git a/dotfiles/.local/bin/pacsync b/dotfiles/.local/bin/pacsync index f96996a..9e745c8 100755 --- a/dotfiles/.local/bin/pacsync +++ b/dotfiles/.local/bin/pacsync @@ -1,5 +1,8 @@ #!/bin/sh +# Run only if user logged in (prevent cron errors) +w | grep "^$USER\W" >/dev/null || exit + # Don't try to sync if pacman is already running if pidof pacman; then exit @@ -12,12 +15,12 @@ wget -q --tries=5 --timeout=20 --spider 1.1.1.1 > /dev/null || exit # Source the needed env variables so that it can function properly from cron . ~/.cache/sessionenv -notify-send " System upgrade" "Syncing repositories and downloading packages..." +notify-send " System upgrade" "Syncing repositories and downloading packages..." touch ~/.cache/pacsynclive killall -41 waybar -sudo pacman -Syuw --noconfirm || notify-send " System upgrade" \ +sudo pacman -Syuw --noconfirm || notify-send " System upgrade" \ "Error downloading updates. Check your internet connection or that you have the required permissions" rm -f ~/.cache/pacsynclive @@ -26,5 +29,5 @@ killall -41 waybar upno=$(pacman -Qu | wc -l) if [ $upno -lt 0 ]; then - notify-send " System upgrade" "Repository sync finished. $upno updates are available" + notify-send " System upgrade" "Repository sync finished. $upno updates are available" fi |