Skip to content

Commit

Permalink
mailcheck: allow users to have variables in $MBLAZE/profile
Browse files Browse the repository at this point in the history
Fixes issue haqistan#1 by adding a new function to query option in the user
profile.

Thi version is both more robust and reliable when a user uses variables
(like $HOME, $BLAZE or anything else) in his profile to specify path to
commands or files.

With this patch, user can now have this:
MailCheckIndexCommand: mairix -f $MBLAZE/mairixrc

It will be automatically transformed as: mairix -f
/whatever/path/to/file/mairixrc at runtime.

All the options are now using getmblazeopt to be filled.

This commit is replacing 517694b
  • Loading branch information
xmailla committed Jan 4, 2025
1 parent 00d42d7 commit e19dc44
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions mailcheck
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,38 @@ MBLAZE=${MBLAZE-$HOME/.mblaze}
profile="$MBLAZE/profile"

sleep=$1
[ -z "$sleep" ] && sleep=$(mhdr -h MailCheckSleep $profile)
[ -z "$sleep" ] && sleep=30
check_cmd=$(mhdr -h MailCheckCommand $profile)
[ -z "$check_cmd" ] && check_cmd="fdm -q fetch"
check_lockf=$(mhdr -h MailCheckLockFile $profile)
[ -z "$check_lockf" ] && check_lockf=$HOME/.fdm.lock
index_cmd=$(mhdr -h MailCheckIndexCommand $profile)
[ -z "$index_cmd" ] && index_cmd="mairix -p"
[ "$index_cmd" = "-" ] && index_cmd=""
date_fmt=$(mhdr -h MailCheckDateFmt $profile)
[ -z "$date_fmt" ] && date_fmt="%Y-%m-%d %H:%M"

sleeper_pid=0

ts () {
date +"$date_fmt"
}

getmblazeopt () {
[[ -n $1 ]] && mhdr -h $1 $profile | envsubst && return 0
return 1
}

check_cmd=$(getmblazeopt MailCheckCommand)
check_cmd=${check_cmd:-"fdm -q fetch"}

sleep=${1:-$(getmblazeopt MailCheckSleep)}
sleep=${sleep:-30}

check_lockf=$(getmblazeopt MailCheckLockFile)
check_lockf=${check_lockf:-"$HOME/.fdm.lock"}

index_cmd=$(getmblazeopt MailCheckIndexCommand)
index_cmd=${index_cmd:--}
if [[ $index_cmd == "-" ]]; then
index_cmd=""
else
index_cmd=${index_cmd:-"mairix -p"}
fi

date_fmt=$(getmblazeopt MailCheckDateFmt)
date_fmt=${date_fmt:-"%Y-%m-%d %H:%M"}

shleep () {
sleep $1 >/dev/null 2>&1 & sleeper_pid=$!
echo $(ts) sleeping ...
Expand Down

0 comments on commit e19dc44

Please sign in to comment.