Last Updated: February 25, 2016
· oelmekki

Prompt for user input in mutt macro

You can prompt for a user input (ask for confirmation, ask for filename) in a prompt macro, despite documentation stating it's impossible.

For that, take advantage of the source command : it's supposed to read a muttrc file, but can execute scripts that output mutt commands.

#!/usr/bin/env bash
echo "Archive tagged messages? [yes]/no : " >&2
read answer

if [[ $answer == "" || $answer == "yes" || "$answer" == "y" ]]; then
  printf "push <tag-prefix-cond><save-message>=Archive<return>$<return>"
  printf "push <return>"

Be sure to redirect any UI text to stderr, or mutt will try to interpret it.

You can then use it in macro :

macro index A "<enter-command>source '/usr/local/bin/mutt-archive-confirm |'<return>" "archive tagged messages"
Say Thanks
Filed Under