commit - 3767d3c69ecc072bd6e0d6cb4832b3f19e27adc1
commit + b8db2d1101c7378934f0721b0b0f778963b07a0e
blob - 829de715dee4f5a22a53bd7084db0584d96b98bf
blob + 5e4d3c851d20d435c4024f75a257f06a185e49a7
--- gpm
+++ gpm
use strict;
use warnings;
-use IPC::Open2;
-use Getopt::Std;
use File::Basename;
use File::Path 'make_path';
+use Getopt::Std;
+use IPC::Open2;
use POSIX ':sys_wait_h';
use Digest::SHA 'sha256';
$cmd .= " -r $r" if defined $r;
- getopts('m') or usage;
- $#ARGV >= 0 or usage;
+ getopts('m') or usage();
+ $#ARGV >= 0 or usage();
my $outfile = $ARGV[0];
ckpath $outfile or die "bad path: $outfile\n";
system "stty echo";
die "Sorry\n" if $sec ne $sec2;
undef $sec2;
- } else { while (<STDIN>) { $sec .= $_; } }
+ } else {
+ while (<STDIN>) { $sec .= $_; }
+ }
my $pid = open2(my $reader, my $writer, $cmd);
print $writer $sec;
undef $sec;
close $writer;
- my $out;
+ my $out = '';
while (<$reader>) { $out .= $_; }
waitpid $pid, 0;
$? == 0 or exit 1;
my $d = dirname $outfile;
- make_path($d, {mode => 0700});
+ make_path $d, {mode => 0700};
umask 0377;
unless (open FH, ">$outfile") {
- prunetree($d);
+ prunetree $d;
die "couldn't open $outfile for writing: $!\n";
}
unless (print FH $out) {
- prunetree($d);
+ prunetree $d;
die "couldn't write to $outfile: $!\n";
}
}
# environment variable if defined.
sub ls {
my $cmd = $ENV{GPM_LSCMD};
+
unless (defined $cmd) {
opendir my $dh, "." or die "couldn't open directory .: $!\n";
while (readdir $dh) {
}
$cmd = "ls" unless defined $cmd;
}
- system($cmd);
+ system $cmd;
$? == 0 or exit 1;
}
# mv: safely rename $ARGV[0] to $ARGV[1].
sub mv {
- $#ARGV >= 1 || usage;
+ $#ARGV >= 1 || usage();
my ($from, $to) = @ARGV;
+
ckpath $from or die "bad path $from\n";
ckpath $to or die "bad path $to\n";
-e $to and die "$to already existst\n";
# rm: unlink arguments, asking each time.
sub rm {
- $#ARGV >= 0 || usage;
+ $#ARGV >= 0 || usage();
for (@ARGV) {
my $f = $_;
unless (ckpath $f) {
# get: decrypt file, and return plaintext.
sub get {
- $#ARGV >= 0 or usage;
+ $#ARGV >= 0 or usage();
my $file = $ARGV[0];
+
ckpath $file or die "bad path $file\n";
$file = shellquote(cklegacy $file);
my $out = `$gpg -d $file`;
$? == 0 or exit 1;
+
return $out;
}
}
}
-getopts('g:d:r') or usage;
+getopts('g:d:r') or usage();
-$#ARGV >= 0 or usage;
+$#ARGV >= 0 or usage();
my $cmd = $ARGV[0];
shift @ARGV;
-$gpg = $opt_g;
-$gpg = $ENV{GPM_GPG} unless defined $gpg;
-$gpg = "gpg" unless defined $gpg;
+$gpg = $opt_g // $ENV{GPM_GPG} // "gpg";
-my $gpmd = $opt_d;
-defined $gpmd or $gpmd = $ENV{GPM_DIR};
+my $gpmd = $opt_d // $ENV{GPM_DIR};
unless (defined $gpmd) {
if (defined $ENV{XDG_DATA_HOME}) {
$gpmd = $ENV{XDG_DATA_HOME} . "/gpm";
}
}
-make_path($gpmd, {mode => 0700});
+make_path $gpmd, {mode => 0700};
chdir $gpmd or die "couldn't change directory to $gpmd: $!\n";
for ($cmd) {
-if (/^a/) { add; last; }
-if (/^c/) { copy; last; }
-if (/^l/) { ls; last; }
-if (/^m/) { mv; last; }
-if (/^r/) { rm; last; }
-if (/^s/) { show; last; }
- usage;
+if (/^a/) { add(); last; }
+if (/^c/) { copy(); last; }
+if (/^l/) { ls(); last; }
+if (/^m/) { mv(); last; }
+if (/^r/) { rm(); last; }
+if (/^s/) { show(); last; }
+ usage();
}