commit afdbc7b01799591096e1c2e73dea99129a22d5ff from: Omar Polo date: Wed Jun 29 10:56:05 2022 UTC replace the 'write' subcommand with 'tee' tee allows to create pipelines and handy one-liners: $ password-generator | plass tee foo | clip A foo.gpg Created commit xyz to accomodate it, the output from 'got commit' is redirected to stderr so it doesn't interfere with the flow of the data. commit - 19df8a205a71a011b3834e975eecdf3532a20829 commit + afdbc7b01799591096e1c2e73dea99129a22d5ff blob - af2de76fafffc3d3e4315dacb566c6e956c716db blob + 7629c1752f8cf5a2e700f2766fa64740812c32e7 --- plass +++ plass @@ -54,8 +54,8 @@ my %subcmd = ( oneshot => [\&cmd_oneshot, "[-c chars] [-l length]"], regen => [\&cmd_regen, "[-c chars] [-l length] entry"], rm => [\&cmd_rm, "entry"], + tee => [\&cmd_tee, "[-q] entry"], tog => [\&cmd_tog, "arguments ..."], - write => [\&cmd_write, "entry"], ); pod2usage(1) unless defined $subcmd{$cmd}; my ($fn, $usage) = @{$subcmd{$cmd}}; @@ -177,8 +177,19 @@ sub got_rm { } sub got_ci { - system ($got, 'commit', '-m', shift); - die "failed to commit changes: $!" if $? == -1; + my $pid = fork; + die "failed to fork: $!" unless defined $pid; + + if ($pid ne 0) { + wait; + die "failed to commit changes" if $?; + return; + } + + open (STDOUT, ">&", \*STDERR) + or die "can't redirect stdout to stderr"; + exec ($got, 'commit', '-m', shift) + or die "failed to exec $got: $!"; } @@ -297,13 +308,12 @@ sub cmd_rm { got_ci "-$name"; } -sub cmd_tog { - chdir $store; - exec $tog, @ARGV; -} - -sub cmd_write { - GetOptions('h|?' => \&usage) or usage; +sub cmd_tee { + my $q; + GetOptions( + 'h|?' => \&usage, + 'q' => \$q, + ) or usage; usage if @ARGV ne 1; my $name = shift @ARGV; @@ -311,11 +321,17 @@ sub cmd_write { my $pass = readpass "Enter the password: "; writepass($file, $pass); + say $pass unless $q; got_add $file; - got_ci "+$name"; + got_ci (-f $file ? "update $name" : "+$name"); } +sub cmd_tog { + chdir $store; + exec $tog, @ARGV; +} + __END__ =head1 NAME @@ -327,7 +343,7 @@ B - manage passwords B I [-h] [arg ...] Valid subcommands are: cat, find, gen, got, mv, oneshot, regen, rm, -tog, write. +tee, tog. =head1 DESCRIPTION @@ -384,16 +400,16 @@ Like B but re-generates a password in-place. Remove the password I from the store. +=item B [B<-q>] I + +Prompt for a password, persist it in the store under the given +I name and then print it again to standard output. + =item B I Execute tog(1) in the password store directory with the given I. -=item B I - -Prompt for a password and persist it in the store under the given -I name. - =back =head1 CREATING A PASSWORD STORE