aboutsummaryrefslogtreecommitdiffstats
path: root/icevault
diff options
context:
space:
mode:
Diffstat (limited to 'icevault')
-rwxr-xr-xicevault24
1 files changed, 22 insertions, 2 deletions
diff --git a/icevault b/icevault
index 445c3aa..1c0ba1b 100755
--- a/icevault
+++ b/icevault
@@ -81,6 +81,7 @@ sub usage($) {
print $fh "Usage: $0 [OPTIONS] [fill] scheme://hostname/identity\n"
." or: $0 [OPTIONS] insert [identity]\n"
." or: $0 [OPTIONS] dump scheme://hostname/identity\n"
+ ." or: $0 [OPTIONS] clip scheme://hostname/identity\n"
. "Consult the manual page for more information.\n";
exit $rv;
}
@@ -275,7 +276,7 @@ sub loadIdentityFile($) {
or error "Can't fork: %s", $!;
my $str = do { local $/ = undef; <$fh> };
waitpid $pid, 0;
- error "C<%s> exited with value %d", $CONFIG{gpg}, ($? >> 8) if $?;
+ error "C<%s> exited with value %d", $CONFIG{gpg}, ($? >> 8) if $? and $? != -1;
close $fh;
# the cleartext's charset is always UTF8
@@ -297,7 +298,7 @@ sub saveIdentityFile($$) {
print $infh encode_utf8(YAML::Tiny::Dump $form); # dump the form as UTF8
close $infh;
waitpid $pid, 0;
- error "C<%s> exited with value %d", $CONFIG{gpg}, ($? >> 8) if $?;
+ error "C<%s> exited with value %d", $CONFIG{gpg}, ($? >> 8) if $? and $? != -1;
$outfh->close;
my $parent_dir = $file =~ s/\/[^\/]+$//r;
@@ -716,6 +717,25 @@ elsif ($command eq 'dump') {
print STDOUT (defined $LOCALE ? $LOCALE->encode(YAML::Tiny::Dump $form) : YAML::Tiny::Dump $form);
}
+elsif ($command eq 'clip') {
+ usage(1) unless $#ARGV == 0;
+ my $id = shift;
+ my $file = getIdentityFile $id;
+ error "No such identity C<%s>", $id unless -f $file;
+
+ my $form = loadIdentityFile $file;
+ my $pw = first { $_->{type} eq 'password' } @{$form->{fields}};
+ error "No password found in C<%s>", $id unless defined $pw;
+
+ my $pid = open my $fh, '|-', qw/xclip -loop 1 -selection clipboard/
+ or error "Can't fork: %s", $!;
+ print $fh $LOCALE->encode($pw->{value});
+ close $fh;
+ waitpid $pid, 0;
+ error "C<%s> exited with value %d", 'xclip', ($? >> 8) if $? and $? != -1;
+ exit 0;
+}
+
else {
myprintf "Unknown command: C<%s>", $command;
usage(1);