---
date: 2022-03-26T14:40:00Z
update: 2024-05-09T00:36:30Z
---
tl;dr: add the following to your `~/.tmux.conf`, and start a new tmux session.
MAIL_ICON=" #(cat /var/spool/mail/$USER | grep ' ' && echo '✉') " set -g status-right "$MAIL_ICON" set -g status-interval 60
---
My town tmux session usually includes chat and 1-2 other applications open. However, writing town mail is not a regular activity for me (unless someone has already started a conversation with the likelihood of a reply), which often means for weeks or months forgetting to check my inbox. In this situation, it is helpful to have a mail indicator to alert me whenever there is a new message.
The main piece to add to your tmux configuration (by default `~/.tmux.conf`) is:
MAIL_ICON=" #(cat /var/spool/mail/$USER | grep ' ' && echo '✉') "
This line checks the user mail spool and outputs a little envelope icon if it finds a space character in the file contents (a properly formatted mail message includes headers and plenty of space characters). When you open Alpine or fetch mail from another client, the mail client will copy all messages to the inbox and the mail file will be empty again.
You can set it to display on the left or right side of the status bar: `set -g status-left "$MAIL_ICON"` or `set -g status-right "$MAIL_ICON"`. `set -g status-interval [seconds]` determines the refresh rate, including any other system information indicators in the bar. My `status-interval` is set to 60 seconds, which goes well with a clock displayed in [hours]:[minutes] in my status bar, and my disk usage does not change significantly to warrant more frequent monitoring.
If you come upon this post and the indicator does not work, the most likely explanation is the mail file location is incorrect or has changed. In some systems it might be `/var/mail/$USER` or a custom `$MAIL` variable. Check with your friendly local admin for the correct path.
The variants below did *not* work.
MAIL_ICON=" #(cat $HOME/mbox | grep 'Status: O' && echo '✉') "
This looks in Alpine's mbox for unread messages. Alpine has to fetch the mail and add it to the mbox, and if Alpine isn't running, the mbox won't be updated.
MAIL_ICON=" #(has_mail=`cat /var/spool/mail/$USER`; test -z $has_mail || echo '✉') "
This is valid Bash, maybe tmux did not like custom variables. Also tried rephrasing it with the `if` conditional instead of custom variables, but no go either. It should work if it were moved to its own script file and called from within the tmux config, but there is no need to add another file if there is a simpler solution using only the tmux config.