Macro to apply on current mailbox

Oleg A. Mamontov oleg at mamontov.net
Mon Feb 15 21:00:35 UTC 2021


On Mon, Feb 15, 2021 at 07:13:05PM +0100, Angel M Alganza wrote:
>On Mon, Feb 15, 2021 at 09:43:39AM -0800, Kevin J. McCarthy wrote:
>>On Mon, Feb 15, 2021 at 10:35:25AM +0100, Angel M Alganza wrote:
>>>	# Need to upgrade to > 1.8.0 (setenv)
>>>	folder-hook . 'set my_folder=$folder;set folder="XXX";set visual=^'
>>>	folder-hook . 'setenv MYSYNCFOLDER $visual'
>>>	folder-hook . 'set folder=$my_folder'
>>>	macro index \! "!/usr/bin/mbsync \$MYSYNCFOLDER\n"
>
>>You've overridden <shell-escape>, bound to '!' by default, with your 
>>macro.  But then you are trying to use '!' inside the macro.  That's 
>>a loop - instead of calling <shell-escape> you are calling your 
>>macro inside the macro.
>
>Oh boy!  That's embarrassing (even though I didn't write the macro, 
>but I got it somewhere or from someone).  LOL
>
>Also, I don't want to override <shell-escape> at all!  I was just 
>using ! because it happens to be beside the " in my (Spanish) keyboard 
>and now I'm using " in a macro to fetch my inbox like so:
>
>  macro index  \" "!/usr/bin/mbsync inbox\n"
>  macro pager  \" "!/usr/bin/mbsync inbox\n"
>
>But, actually, I won't be needing that when I can fetch the current 
>maildir I'm working in with the new macros I'm trying to get working, 
>so, I'll be using " for that (in case I'm not missing something with 
>overriding ", too).
>
>>Try (untested):
>> macro index \! "<shell-escape>/usr/bin/mbsync \$MYSYNCFOLDER\n"
>
>That somehow works, as does:
>
>  macro index \" "!/usr/bin/mbsync \$MYSYNCFOLDER\n"
>
>But, when I use it, I get:
>
>  No channel or group named '~/mail/mutt/' defined.
>
>It seems that the folder hooks are fetching the current maildir name 
>relative to my home, but mbsync would need its name relative to 
>~/mail/?
>Maybe adding some grep rule into the hooks would make that ~/mail/ 
>part go away?

The below approach works for me, probably it can be helpful somehow:

.muttrc
---
# the very first folder-hook
folder-hook . "source ~/.mutt/on-folder-change.muttrc"
---

# .mutt/on-folder-change.muttrc
---
set record = ^
set record = `echo $record | sed 's#.*/##'`
macro index,pager <esc>o "<sync-mailbox>:unset wait_key<enter><shell-escape>clear; mbsync full:$record<enter>:set wait_key<enter>" "sync current folder"
---

>Cheers,
>Ángel

-- 
Cheers,
Oleg A. Mamontov

mailto: oleg at mamontov.net

skype:  lonerr11
cell:   +7 (903) 798-1352


More information about the Mutt-users mailing list