From 2982c60270152f229f2c414e30e6de510c8cfbe3 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Tue, 17 Mar 2015 02:37:56 +0100 Subject: clip command --- icevault | 24 ++++++++++++++++++++++-- icevault.1 | 6 ++++++ 2 files changed, 28 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); diff --git a/icevault.1 b/icevault.1 index 4b18121..a58a1e1 100644 --- a/icevault.1 +++ b/icevault.1 @@ -9,6 +9,8 @@ IceVault \- IceVault client user interface .B icevault\fR [\fIOPTIONS\fR] \fBinsert\fR [\fIidentity\fR] .br .B icevault\fR [\fIOPTIONS\fR] \fBdump\fR \fIscheme\fR://\fIhostname\fR/\fIidentity\fR +.br +.B icevault\fR [\fIOPTIONS\fR] \fBclip\fR \fIscheme\fR://\fIhostname\fR/\fIidentity\fR .SH DESCRIPTION @@ -75,6 +77,10 @@ Decrypt the \fIidentity\fR file and dump its content on the standard output. Note that while the output is a valid YAML document, original formatting may not be preserved; in particular, comments and empty lines are stripped. +.TP +.B clip\fR \fIscheme\fR://\fIhostname\fR/\fIidentity\fR +Decrypt the \fIidentity\fR file and copy the first password to the +clipboard using \fIxclip\fR(1), with a maximum number of pastes of 1. .SH OPTIONS -- cgit v1.2.3