Hi mutters,

here it is a bash script which fetches the message id from a mail
message, assemblates a corresponding G-mane address and eventually
launches a browser on it.

Try:
gmane-find -h 
to see how it works.

The browser command has to be defined at the beginning of the script.

Possible use with mutt:

macro index,pager G "<pipe-message>gmane-find -tb<return>" "launch the browser 
to the corresponding G-mane archive page"

Hope you'll find it useful :-).

Cheers.
-- 
mutt random tip #4
You can improve the modularity of your mutt configuration using the source 
command.
Usage:
source <filename>
#!/bin/bash  

E_BADARGS=65

# change this to your web browser 
browser_command=/usr/bin/firefox

# eagerly strip the leading part of the script filename (/foo/bar/baz -> baz)
my_name=${0##*/}

usage() {
    cat <<EOT
Usage: $my_name <options> [<filename>] 

Extract the message-ID from the mail, format a corresponding gmane address 
and eventually access it with the command \"$browser_command\".
If no filename is provided then process stdin.

Options:
-h|--help|--usage          Print this help
-b|--browse                Launch "$browser_command" on the found url.
-a|--article               Print or browse the gmane article url (default)
-t|--thread                Print or browse the gmane thread url
EOT
}

# reset the arguments strings using the parsing facility provided by getopt
args=$(getopt -n $my_name -lhelp -lusage -lbrowse -larticle -lthread -o habt -- 
$@)

if ! [ $? = '0' ]; then
        echo "$my_name: parsing error." 2>&1;
        usage 2>&1
        exit $E_BADARGS
fi

eval set -- $args

browse=off
url_type="article"

# command line arguments parsing
# continue when there are arguments to parse
while [ -n "$1" ]; do
    case "$1" in
          -h|--help|--usage) 
                usage 
                exit 0;;
          -a|--article)
                url_type="article"
                ;;
          -t|--thread)
                url_type="thread"
                ;;
          -b|--browse)
                browse=on;
                ;;
      --)
                shift
        break;;
        esac
    shift
done

message_id=$(grep -i "^Message-id:" $1 | sed -e 's/.*<\(.*\)>/\1/')
if [ -z "$message_id" ]; then
        echo "$my_name: no message-id found in input or no input." 1>&2
        exit 1
fi

if [ $url_type = "thread" ]; then
        url="http://thread.gmane.org/$message_id";
else
        url="http://mid.gmane.org/$message_id";
fi

echo $url

if [ $browse = "on" ]; then
    $browser_command $url
fi

exit 0

Reply via email to