Background: I use offlineimap to download emails, and use sidebar to switch folders to display. Previously, I hard-coded to only synchronize "INBOX" folder. Here is part of my .muttrc related:
macro index o "<sync-mailbox>.<shell-escape>offlineimap -qf INBOX<enter>.<sync-mailbox>" "run offlineimap to sync inbox"
Goal: I'd like to synchronize the current opened folder. Essentially, I want to get a variable that contains the name of the currently opened folder, and replace the hard-coded "INBOX" with the name. However, I failed to find out how to get the currently opened folder. And the "folder-hook" method seems not work.
As a workaround, use a folder hook that on entering $folder rebinds the binding to only update $folder. For example
folder-hook . 'macro index o "<shell-escape>offlineimap -qo >/dev/null 2>&1 &<enter><sync-mailbox><refresh>"'
folder-hook =INBOX$ 'macro index o "<shell-escape>offlineimap -qo -f INBOX >/dev/null 2>&1 &<enter><sync-mailbox><refresh>"'
folder-hook =INBOX.Sent$ 'macro index o "<shell-escape>offlineimap -qo -f INBOX.Sent >/dev/null 2>&1 &<enter><sync-mailbox><refresh>"'