diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2015-03-17 02:37:56 +0100 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2015-03-17 02:38:24 +0100 |
commit | 2982c60270152f229f2c414e30e6de510c8cfbe3 (patch) | |
tree | 1200e424ff0c9e22a00a81fd343a4fdb27abfbcd | |
parent | 459e20dad92e1ce276286aa7821c7bef3c4743fd (diff) |
clip command
-rwxr-xr-x | icevault | 24 | ||||
-rw-r--r-- | icevault.1 | 6 |
2 files changed, 28 insertions, 2 deletions
@@ -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); @@ -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 |