From 546a3a211a0d59f14edbd97c1990476e84a46247 Mon Sep 17 00:00:00 2001 From: Raul Benencia Date: Sun, 24 May 2020 13:44:14 -0700 Subject: Add bin/ repo from home-bin/ repo --- bin/mutt-fetchbug | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100755 bin/mutt-fetchbug (limited to 'bin/mutt-fetchbug') diff --git a/bin/mutt-fetchbug b/bin/mutt-fetchbug new file mode 100755 index 0000000..93ffc58 --- /dev/null +++ b/bin/mutt-fetchbug @@ -0,0 +1,161 @@ +#!/usr/bin/perl -w +# +# mutt-fetchbug, extensively based off of +# mutt-notmuch - notmuch (of a) helper for Mutt +# +# Copyright: © 2011 Stefano Zacchiroli +# License: GNU General Public License (GPL), version 3 or above +# +# Differences between mutt-notmuch and mutt-fetchbug are +# Copyright: © 2012 Ryan Kavanagh +# License: GNU General Public License (GPL), version 3 or above +# +# See the bottom of this file for more documentation. +# A manpage can be obtained by running "pod2man mutt-fetchbug > mutt-fetchbug.1" + +use strict; +use warnings; + +use File::Path; +use Getopt::Long; +use Pod::Usage; + +# search($btsmbox, $query) +# Fetch bugs matching $query with bts; store results in $btsmbox +sub search($$) { + my ($btsmbox, $query) = @_; + + system("bts --cache-mode=mbox cache $query" + . " && ln -fs ~/.cache/devscripts/bts/$query.mbox $btsmbox"); +} + +sub search_action($$@) { + my ($interactive, $btsmbox, @params) = @_; + + if (! $interactive) { + fetch($btsmbox, join(' ', @params)); + } else { + my $query = ""; + my $done = 0; + while (! $done) { + print "bug number ('?' for man): "; + chomp($query = ); + if ($query eq "?") { + system("man bts"); + } elsif ($query eq "") { + $done = 1; # quit doing nothing + } else { + search($btsmbox, $query); + $done = 1; + } + } + } +} + +sub die_usage() { + my %podflags = ( "verbose" => 1, + "exitval" => 2 ); + pod2usage(%podflags); +} + +sub main() { + my $btsmbox = "$ENV{HOME}/.cache/mutt_btsresults"; + my $interactive = 0; + my $help_needed = 0; + + my $getopt = GetOptions( + "h|help" => \$help_needed, + "o|output-mbox=s" => \$btsmbox, + "p|prompt" => \$interactive); + if (! $getopt || $#ARGV < 0) { die_usage() }; + my ($action, @params) = ($ARGV[0], @ARGV[1..$#ARGV]); + + if ($help_needed) { + die_usage(); + } elsif ($action eq "search" && $#ARGV == 0 && ! $interactive) { + print STDERR "Error: no search term provided\n\n"; + die_usage(); + } elsif ($action eq "search") { + search_action($interactive, $btsmbox, @params); + } else { + die_usage(); + } +} + +main(); + +__END__ + +=head1 NAME + +mutt-fetchbug - 'bts show' frontend for Mutt + +=head1 SYNOPSIS + +=over + +=item B [I