MH (and nmh, it's newer derivative) is a mail reader made up of a number of separate commands so you continue to use your existing shell (zsh) when interacting with it. This is in contrast to other command-line based mail readers such as BSD mail, mush and nail which include their own command-line handling. For this reason, it appeals to some power Zsh users because all the features of the zsh line editor continue to be available. This also means that there is a good deal of scope for writing such things as zsh functions to wrap around MH commands so this page is for anyone wanting to share any such functions ot other tips.

  • displaying messages by just typing a message number. This is typically done with a directory full of hard links to a script but this is a little less messy. Only problem with this though is that correction can get in the way.
preexec() { [[ $1 = <-> ]] && function $1 { show $0; unfunction $0 } }
  • short aliases to MH commands for people accustomed to mush commands:
alias d=rmm
alias dn='d;n'
alias f='scan cur'
alias h=scan
alias n=next
alias p=prev
alias s=refile
  • new mail notification. zsh doesn't support MH mailboxes. This function sort-of works and could do with improvement:
periodic() {
  local mails
  set -A mails ~/Mail/inbox/*(Nms-60)
  if (( $#mails )); then
    grep -q unseen ~/Mail/inbox/.mh_sequences && h +inbox unseen
  • file zsh mailing list messages away by message number:
zfile() {
  local indir outdir msg list dest
  for list in workers users; do
    outdir="$(mhpath +sw/zsh/$list)"
    for msg in $(pick --mailing-list $list -and --x-seq '' "$@" 2>/dev/null); do
      [[ $msg = '0' ]] && break
      dest="$(sed -n 's/^X-Seq: //p' $indir/$msg)"
      echo $indir/$msg '->' $outdir/$dest
      mv -i $indir/$msg $outdir/$dest
code/scripts/zshmh.txt · Last modified: 2014/02/06 10:04 by opk