[Home]QueryCommand

MuttWiki | RecentChanges | Preferences | EDITwiki

Did you ever feel the need for some addressbook "better" than mutt's internal alias management?

By setting $query_command in your .muttrc you can tell mutt to use an external program for looking up addresses when invoking the "Query" command (hit '?' for mutt-keybinding). query_command is used as well for address completion in any prompt for address entry, default by hitting ^T.

Selecting multiple lines in query menu

The query command can return multiple addresses. If you want to select multiple addresses it does not work if you tag them with 't' and then hit return. What works for me is pressing ;-m.

Different tools for queries

Using Multiple Query Tools

The above tools are great if all your addresses are in one place, but what if you've got multiple sources to search? (My need for a solution for this came from having to search the corporate LDAP directory and abook's records.)

Fortunately, many *nix distributions (Debian, Redhat both confirmed) come with the perfect tool for combining these resources. Additionally, this method can be used with the majority of the tools listed above and with most stand-alone scripts written for mutt on the interwubs:

user@myhost:~/.mutt/address-providers$ pwd
/home/user/.mutt/address-providers
user@myhost:~/.mutt/address-providers$ ls -l
total 8
-rwx------ 1 user user  127 2008-04-16 22:43 dummy_addresses
-rwx------ 1 user user 1708 2008-04-16 18:58 mutt_ldap
user@myhost:~/.mutt/address-providers$ cat dummy_addresses 
#!/bin/bash
echo "hello@hello.com  buuuuuuuuuh     HELLOOOOOOOOOOOOOOO"
echo "gfdgfd@43hg4.net Roger Smith     Properly Formed Entry"
user@myhost:~/.mutt/address-providers$ grep query ~/.muttrc
set query_command = "echo ; /bin/run-parts -a '%s' /home/user/.mutt/address-providers/|grep '@'"

To add a new search mechanism, just drop the file into the address-providers directory. Each script in address-providers should

  1. be executable
  2. have a name containing only these characters: [a-zA-Z0-9-_]
  3. take a query as its first parameter

As a result of (2), to stop any script from being used just pop a period in its name: "mv Broken_Script Broken_Script.bother"

NB1 In my example, the "dummy_addresses" provider is there simply to prove to yourself that the mechanism is working. Remove it after testing.

NB2 A couple of points about the query_command:

  1. The initial "echo;" is there because mutt doesn't use or display the first line as a potential address; it doesn't seem to be used anywhere with my fairly stock mutt install, but that doesn't mean it's useless. Change the echo statement to output anything you want
  2. The final "grep '@'" is a nasty way of removing each script's initial reporting line that mutt would normally remove itself, as per point (1). It works as long as you're only looking for addresses that definitely use @'s, and you don't need each script's reporting line, and no reporting line contains an @. For most people, none of this is a problem - just use it as is. If you've got a problem with this, then you probably know enough to alter the command to achieve what you want ... -- jaycee

MuttWiki | RecentChanges | Preferences | EDITwiki
Read EDITwiki in nav-bar!!! | View other revisions
Last edited January 20, 2010 10:06 am by Sfisher (diff)
Search: