]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei q --save: clobber config file on repeats
authorEric Wong <e@80x24.org>
Fri, 16 Apr 2021 23:10:35 +0000 (16:10 -0700)
committerEric Wong <e@80x24.org>
Sat, 17 Apr 2021 10:00:45 +0000 (10:00 +0000)
A user may wish to clobber/refine existing search parameters
by issuing "lei q --save" again.  Support that by overwriting
the lei.saved-search state file entirely.

We continue to preserve over.sqlite3 for deduplication purposes.

This way, we don't get something redundant like:

[lei]
q = term1
q = term2
q = term1
q = term2
q = term3

...whenever a user wants to refine their search.  Instead,
we'll just have:

[lei]
q = term1
q = term2
q = term3

On the second go.

lib/PublicInbox/Config.pm
lib/PublicInbox/LeiSavedSearch.pm
lib/PublicInbox/Reply.pm

index 26ac298eddb86f2256c4618d7abef920f7a4b95d..603dad983657441a68694bb7cc2bb19156794232 100644 (file)
@@ -559,4 +559,13 @@ sub json {
        };
 }
 
+sub squote_maybe ($) {
+       my ($val) = @_;
+       if ($val =~ m{([^\w@\./,\%\+\-])}) {
+               $val =~ s/(['!])/'\\$1'/g; # '!' for csh
+               return "'$val'";
+       }
+       $val;
+}
+
 1;
index a8bf470be4738db3733ed0f39bbe196c32c0d92d..932b2aa4c728d0b758526289b6c7f90f21ff19a8 100644 (file)
@@ -13,6 +13,8 @@ use PublicInbox::Spawn qw(run_die);
 use PublicInbox::ContentHash qw(git_sha);
 use Digest::SHA qw(sha256_hex);
 
+*squote_maybe = \&PublicInbox::Config::squote_maybe;
+
 sub lss_dir_for ($$) {
        my ($lei, $dstref) = @_;
        my @n;
@@ -44,7 +46,13 @@ sub new {
                require File::Path;
                File::Path::make_path($dir); # raises on error
                $self->{-cfg} = {};
-               $self->{'-f'} = "$dir/lei.saved-search";
+               my $f = $self->{'-f'} = "$dir/lei.saved-search";
+               open my $fh, '>', $f or return $lei->fail("open $f: $!");
+               my $sq_dst = squote_maybe($dst);
+               print $fh <<EOM or return $lei->fail("print $f: $!");
+; to refresh with new results, run: lei up $sq_dst
+EOM
+               close $fh or return $lei->fail("close $f: $!");
                my $q = $lei->{mset_opt}->{q_raw} // die 'BUG: {q_raw} missing';
                if (ref $q) {
                        cfg_set($self, '--add', 'lei.q', $_) for @$q;
index 2a1066d2b47f89b37f14a6b2784c8c8de26c6cbb..79dd46a729dd82be103647b0cf842443b3e4fc97 100644 (file)
@@ -9,15 +9,9 @@ use URI::Escape qw/uri_escape_utf8/;
 use PublicInbox::Hval qw(ascii_html obfuscate_addrs mid_href);
 use PublicInbox::Address;
 use PublicInbox::MID qw(mid_clean);
+use PublicInbox::Config;
 
-sub squote_maybe ($) {
-       my ($val) = @_;
-       if ($val =~ m{([^\w@\./,\%\+\-])}) {
-               $val =~ s/(['!])/'\\$1'/g; # '!' for csh
-               return "'$val'";
-       }
-       $val;
-}
+*squote_maybe = \&PublicInbox::Config::squote_maybe;
 
 sub add_addrs {
        my ($to, $cc, @addrs) = @_;