[neomutt-users] Macro to toggle a string value

Richard Russon rich at flatcap.org
Thu May 20 16:14:17 CEST 2021


On IRC today, someone asked:

    How do I toggle the value of a string between two values?

Here's one solution:

    set my_orig = "apple"
    set my_alt  = "banana"
    macro index <F1> '<enter-command> set status_format="$my_orig" my_tmp="$my_orig" my_orig="$my_alt" my_alt="$my_tmp"; unset my_tmp<enter>'

Note: There's a space after the '<enter-command>'
      This prevents the command being added to the history.

Unpacked:

    set status_format="$my_orig"
    set my_tmp="$my_orig"
    set my_orig="$my_alt"
    set my_alt="$my_tmp"
    unset my_tmp<enter>'

The macro uses some my_var's as temporary storage.
You can create any variable name you like, beginning 'my_'

You could even extend this macro by adding an 'echo' command to the end,
to display the current value.

    macro index <F1> '<enter-command> ...; unset my_tmp; echo $status_format<enter>'

Cheers,
    Rich / FlatCap
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mailman.neomutt.org/pipermail/neomutt-users-neomutt.org/attachments/20210520/71c98644/attachment.sig>


More information about the neomutt-users mailing list