Commit Diff


commit - fe84ad4c60e2348abc1ac14c4cfe4adfebbbb2b8
commit + 104ed24069bfe7e08d69cb3e5cd6789f50684cc5
blob - e1ccc0fe7449a403f41c0960ff8349629e63bbb5
blob + d9d2f23fd1b1d4ab0e300de7d17fbfde11b8de6d
--- gpm
+++ gpm
@@ -18,11 +18,11 @@ my $gpg;
 # usage: print usage information to stderr and exit with error.
 sub usage {
 	die
-"usage: gpm [-g command] [-d dir] add [-m] name\n" .
-"       gpm [-g command] [-d dir] copy [-d delcmd] [-i incmd] [-o outcmd]\n" .
-"                                      [-s time] name\n" .
+"usage: gpm [-g command] [-d dir] add [-Nnm] name\n" .
+"       gpm [-g command] [-d dir] copy [-Nnm] [-d delcmd] [-i incmd]\n" .
+"                                      [-o outcmd] [-s time] name\n" .
 "       gpm [-d dir] rm name ...\n" .
-"       gpm [-g command] [-d dir] show name\n" .
+"       gpm [-g command] [-d dir] show [-Nn] name\n" .
 "       gpm [-d dir] mv from to\n" .
 "       gpm [-d dir] ls\n";
 }
@@ -84,12 +84,12 @@ sub prunetree {
 # Encrypt the secret from stdin, and store the ciphertext in file specified
 # on the command line.
 sub add {
-	our $opt_m;
+	our ($opt_N, $opt_n, $opt_m);
 	my ($r, $sec, $cmd) = (getrecipient(), '', "$gpg -e");
 
 	$cmd .= " -r $r" if defined $r;
 
-	getopts('m') or usage();
+	getopts('Nnm') or usage();
 	$#ARGV >= 0 or usage();
 
 	my $outfile = $ARGV[0];
@@ -106,6 +106,10 @@ sub add {
 		print "Repeat:";
 		my $sec2 = <STDIN>;
 		print "\n";
+		if ($opt_n && !$opt_N) {
+			chomp $sec;
+			chomp $sec2;
+		}
 
 		system "stty echo";
 		die "Sorry\n" if $sec ne $sec2;
@@ -190,6 +194,7 @@ sub rm {
 
 # get: decrypt file, and return plaintext.
 sub get {
+	my ($Nflag, $nflag) = @_;
 	$#ARGV >= 0 or usage();
 	my $file = $ARGV[0];
 
@@ -197,21 +202,24 @@ sub get {
 	$file = shellquote(cklegacy $file);
 	my $out = `$gpg -d $file`;
 	$? == 0 or exit 1;
+	chomp($out) if ($nflag && !$Nflag);
 
 	return $out;
 }
 
 # show: decrypt file, and print plaintext to stdout.
 sub show {
-	print(get @ARGV);
+	our ($opt_N, $opt_n);
+	getopts('Nn') or usage();
+	print(get $opt_N, $opt_n);
 }
 
 # copy: decrypt file, and copy to GPM_COPY_INCMD, delete with GPM_COPY_DELCMD
 # after GPM_COPY_SLEEP seconds if necessary.
 sub copy {
-	our ($opt_d, $opt_i, $opt_o, $opt_s);
+	our ($opt_N, $opt_n, $opt_d, $opt_i, $opt_o, $opt_s);
 
-	getopts('d:i:o:s:') or usage();
+	getopts('Nnd:i:o:s:') or usage();
 	$#ARGV >= 0 or usage();
 
 	my $delcmd =	$opt_d // $ENV{GPM_COPY_DELCMD} // "xclip </dev/null";
@@ -219,7 +227,7 @@ sub copy {
 	my $outcmd =	$opt_o // $ENV{GPM_COPY_OUTCMD} // "xclip -o";
 	my $sleep =	$opt_s // $ENV{GPM_COPY_SLEEP} // 60;
 
-	my $pw = get @ARGV;
+	my $pw = get $opt_N, $opt_n;
 
 	# This is a huge cludge. The reason we have to do copying inside a detached
 	# process is because otherwise the following doesn't work (assuming xclip):