]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/LeiEditSearch.pm
lei edit-search: support relocating lei.q.output
[public-inbox.git] / lib / PublicInbox / LeiEditSearch.pm
1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # "lei edit-search" edit a saved search following "lei q --save"
5 package PublicInbox::LeiEditSearch;
6 use strict;
7 use v5.10.1;
8 use PublicInbox::LeiSavedSearch;
9 use PublicInbox::LeiUp;
10
11 sub lei_edit_search {
12         my ($lei, $out) = @_;
13         my $lss = PublicInbox::LeiSavedSearch->up($lei, $out) or return;
14         my @cmd = (qw(git config --edit -f), $lss->{'-f'});
15         $lei->qerr("# spawning @cmd");
16         $lss->edit_begin($lei);
17         if ($lei->{oneshot}) {
18                 require PublicInbox::Spawn;
19                 waitpid(PublicInbox::Spawn::spawn(\@cmd), 0);
20                 # non-fatal, editor could fail after successful write
21                 $lei->child_error($?) if $?;
22                 $lss->edit_done($lei);
23         } else { # run in script/lei foreground
24                 require PublicInbox::PktOp;
25                 my ($op_c, $op_p) = PublicInbox::PktOp->pair;
26                 # $op_p will EOF when $EDITOR is done
27                 $op_c->{ops} = { '' => [$lss->can('edit_done'), $lss, $lei] };
28                 $lei->send_exec_cmd([ @$lei{qw(0 1 2)}, $op_p ], \@cmd, {});
29         }
30 }
31
32 *_complete_edit_search = \&PublicInbox::LeiUp::_complete_up;
33
34 1;