On 13.09.16 12:08, mimosinnet wrote:
> When the members of the group CoordsM change, I have to change the
> alias.
> 
> Is there a way I can use the definition of the "Address Groups"
> (http://www.mutt.org/doc/manual/#addrgroup) to be able to define an
> alias (http://www.mutt.org/doc/manual/#alias).

Defining group membership the other way, using the "group" command,
would offer the opportunity to do that, _if_ mutt had a -group_alias
option on the group command, for adding the needed group alias.
But it doesn't, and you'd still be editing in two places, anyway.

I've not tried to make the group and group_alias names the same, to ease
the task of e.g. an awk script synthesising the group's alias from the
"alias -group" lines. Leaving it as is, I figure one would need a
linking comment line, e.g.:

# group_alias CoordsMaster CoordsM

placed _before_ the first alias line using either name.

Then a script something like:
                            ----------------
#!/bin/bash

gawk '
$2 ~ /group_alias/   { alias_groups[$4] = $3 ; group_aliases[$3] = $4 }

$1 ~ /alias/ && $2 ~ /-group/   {
   if ($3 in alias_groups)
   {  i = alias_groups[$3]
      alias_lists[i] = alias_lists[i] ", " $4
   }
}

$1 ~ /alias/ && $2 !~ /-group/ {
   if ($2 in group_aliases) printf("%s %s %s\n",$1,$2,substr(alias_lists[$2],3))
   else print
   next
}
   
   { print }      # Print all lines not rewritten.

' ~/.muttrc > /tmp/muttrc
                            ----------------

does the trick for me. To use:

$ muttalgrp                      # Or whatever it should be called.
$ diff ~/.muttrc /tmp/muttrc     # Check shows one line updated, here.
$ mv /tmp/muttrc ~/.muttrc       # You could back-up the old one first.

Caveats:
1) This was quickly cobbled together to see what it'd take to do the job.
   It has only been lightly tested.
2) It catches the required alias lines, and those without -group, but
   not present in group_aliases, but there might be some .muttrc idiom
   which isn't covered.
3) It ought to work for multiple groups in the .muttrc, but it's only been
   tested on one.
4) It doesn't suit my use-case, where not every member of the group
   is allowed to be in the group alias, as the group included in replies
   is a subset of the receipt group. That could perhaps be fiddled with
   either multiple groups or group aliases.

Reply via email to