Search code examples
muttneomutt

Mutt Configuration Based on Current Hostname


I am specifically writing this from the perspective of running Mutt from multiple hosts, but a single source-code-controlled configuration file. Leave it to the devops side that "all" host configurations are being kept adequately in-sync.

So, basically, I want a specific mailbox configuration, effectively based on host type, but more generically, based solely on the hostname command. Essentially, I want the default mailbox to be "correct" for a given host (generally /var/mail/$user for Linux hosts), but I have already defined hotkeys for Mailbox 1-3 that default to hotkeys (basically F2, F# and F4 are the IMAPS mailboxes, and the default is the local system default).

How would you set this up? Currently, I can switch between mailboxes with the proper hotkeys. But, how do I base muttrc "decisions" based on the hostname in which mutt has been run?


Solution

  • This solution should work with mutt and neomutt. The idea is to put host specific configuration in separate files and source them in main configuration file. See example below.

    Files:

    • ~/.neomutt/neomuttrc main config file
    • ~/.neomutt/neomuttrc.host1 host specific config file
    • ~/.neomutt/neomuttrc.host2 host specific config file

    Content of ~/.neomutt/neomuttrc

    # Your main confing file. Here ale all the shared settings. 
    # …
    # source host specific config
    source ~/.neomutt/neomuttrc.`hostname`