mu-wizard

shell script to easily configure mu4e accounts on Emacs
git clone git://git.ckyln.com/~cem/mu-wizard
Log | Files | Refs | LICENSE

commit 907db008dca6b7d06795820fd78ee80fb52d41f3
parent 294327238e5ded52a3b718f8d45cf28973bc5899
Author: Cem Keylan <cem@ckyln.com>
Date:   Tue, 27 Oct 2020 17:09:59 +0300

mailsync: make some simplifications

out():
  remove function and just use die()

cac_dir:
  Use the XDG desktop specification for the cache directory, fallback to
  $HOME/.cache

Diffstat:
Mbin/mailsync | 35++++++++++++++++-------------------
1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/bin/mailsync b/bin/mailsync @@ -1,31 +1,28 @@ #!/bin/sh -out() { printf '%s\n' "$@" >&2 ;} -die() { out "$@"; exit 1 ;} - -pgrep -x mbsync >/dev/null && die "mbsync is already running." - +die() { printf '%s\n' "$@" >&2 ;} notify() { notify-send "mu-wizard" "$2 new mail(s) in '$1' account." ;} +cac_dir=${XDG_CACHE_HOME:-$HOME/.cache} -[ "$1" ] || while read -r chan name; do - case "$chan" in Channel) ;; *) continue; esac - accounts="$accounts $name" -done < "$HOME/.mbsyncrc" - -for acc in ${accounts:=$*}; do - acc=${acc##*/} - mbsync "$acc" & -done; wait +pgrep -x mbsync >/dev/null && die "mbsync is already running." -for acc in $accounts; do - newcount=$(find "$HOME/.local/share/mail/$acc/"*/new \ - -type f -newer "$HOME/.cache/.mailsynclastrun" | wc -l) +[ "$1" ] || { + while read -r chan name; do + case "$chan" in Channel) ;; *) continue; esac + accounts="$accounts '$name'" + done < "$HOME/.mbsyncrc" + eval set -- "$accounts" +} + +for acc; do mbsync "${acc##*/}" & done; wait +for acc; do + newcount=$(find "${MU_MAILDIR:-$HOME/.local/share/mail}/$acc/"*/new \ + -type f -newer "$cac_dir/.mailsynclastrun" | wc -l) [ "$newcount" -gt 0 ] && notify "$acc" "$newcount" done - # Run index update if emacs is available. emacsclient -e "(mu4e-update-index)" >/dev/null 2>&1 || mu index -touch "$HOME/.cache/.mailsynclastrun" +touch "$cac_dir/.mailsynclastrun"