summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-07-21 16:53:18 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-07-21 16:53:18 +0200
commitc22143897b300085d7c8ef37e8fe4850a0c2aca2 (patch)
tree0539b1fff555f396aeabb9af4228ce1d6f4b3033
parent7e948f4248953e135ba9824e15801b313f69c9da (diff)
Make xclip command configurable (->chrome support)
-rw-r--r--Changelog4
-rwxr-xr-xbin/raps240
-rw-r--r--lib/App/Raps2.pm3
-rw-r--r--lib/App/Raps2/UI.pm13
4 files changed, 51 insertions, 9 deletions
diff --git a/Changelog b/Changelog
index f9498df..581ba59 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,7 @@
+git HEAD
+
+ * Make xclip command configurable (for chrome users, mostly)
+
App::Raps2 0.52 - Wed Jul 20 2011
* raps2 add: Fix pwgen usage (remove trailing whitespace)
diff --git a/bin/raps2 b/bin/raps2
index 5aed4c9..0bd8f52 100755
--- a/bin/raps2
+++ b/bin/raps2
@@ -11,7 +11,7 @@ use File::BaseDir qw(data_files data_home);
use File::Slurp qw(read_dir);
use Getopt::Long qw(:config no_ignore_case);
-my ( $default_cost, $no_echo, $paste, $pwgen_cmd );
+my ( $default_cost, $no_echo, $paste, $pwgen_cmd, $xclip_cmd );
our $VERSION = '0.52';
@@ -22,13 +22,15 @@ GetOptions(
'p|pwgen-cmd=s' => \$pwgen_cmd,
'P|paste' => \$paste,
'V|version' => sub { say "raps2 version ${VERSION}"; exit 0 },
+ 'x|xclip-cmd=s' => \$xclip_cmd,
) or cmd_help(1);
my ( $action, @args ) = @ARGV;
my $raps2 = App::Raps2->new(
cost => $default_cost,
- pwgen_cmd => $pwgen_cmd
+ pwgen_cmd => $pwgen_cmd,
+ xclip_cmd => $xclip_cmd,
);
sub file_must_exist {
@@ -81,7 +83,7 @@ sub cmd_add {
}
if ($paste) {
- $raps2->ui->to_clipboard($pass);
+ $raps2->ui->to_clipboard( $pass, $raps2->conf('xclip_cmd') );
}
elsif ( not $no_echo ) {
$raps2->ui->output( [ 'Generated password', $pass ] );
@@ -181,7 +183,7 @@ sub cmd_get {
my $key = $raps2->pw_load( file => $pwfile );
- $raps2->ui->to_clipboard( $key->{password} )
+ $raps2->ui->to_clipboard( $key->{password}, $raps2->conf('xclip_cmd') )
or die("Could not place password in clipboard: ${!}\n");
if ( $key->{extra} ) {
@@ -324,6 +326,8 @@ Decrypt I<account>'s password and store it in the primary X Clipboard. Note
that it can only be pasted once. Prints the content of the multiline B<extra>
field (if present) to stdout.
+See also the B<-x> option.
+
=item B<info> I<account>
Show information about I<account>, does not require the master password.
@@ -378,6 +382,13 @@ Default: pwgen -s 23 1
Show version information.
+=item B<-x>, B<--xclip-cmd> I<command>
+
+Command to run for B<raps2 get>. Set this to C<< xclip -l 2 >> if you are
+using chrome. The password will be available on I<command>'s stdin.
+
+Default: xclip -l 1
+
=back
=head1 EXIT STATUS
@@ -396,6 +407,27 @@ Additional encrypted passwords are stored in F<~/.local/share/raps2/>.
These directories can be changed by setting the B<XDG_CONFIG_HOME> and
B<XDG_DATA_HOME> environment variables.
+The following settings are available in F<~/.config/raps2/defaults>:
+
+=over
+
+=item B<cost> = 12
+
+Default key setup cost. See the B<-c> option.
+
+=item B<pwgen_cmd> = pwgen -s 23 1
+
+Command used to generate passwords. See the B<-p> option.
+
+=item B<xclip_cmd> = xclip -l 1
+
+Command used to place passwords in the clipboard. See the B<-x> option.
+
+=back
+
+Note that commandline arguments always override options set in the
+configuration file.
+
=head1 DEPENDENCIES
=over
diff --git a/lib/App/Raps2.pm b/lib/App/Raps2.pm
index d13aaed..f6a675b 100644
--- a/lib/App/Raps2.pm
+++ b/lib/App/Raps2.pm
@@ -134,11 +134,13 @@ sub create_defaults {
my $cost = $self->{default}{cost} // 12;
my $pwgen_cmd = $self->{default}{pwgen_cmd} // 'pwgen -s 23 1';
+ my $xclip_cmd = $self->{default}{xclip_cmd} // 'xclip -l 1';
write_file(
$self->{xdg_conf} . '/defaults',
"cost = ${cost}\n",
"pwgen_cmd = ${pwgen_cmd}\n",
+ "xclip_cmd = ${xclip_cmd}\n",
);
return;
@@ -151,6 +153,7 @@ sub load_defaults {
$self->{default}{cost} //= $cfg->{_}->{cost};
$self->{default}{pwgen_cmd} //= $cfg->{_}->{pwgen_cmd};
+ $self->{default}{xclip_cmd} //= $cfg->{_}->{xclip_cmd};
return;
}
diff --git a/lib/App/Raps2/UI.pm b/lib/App/Raps2/UI.pm
index 4914b71..ca86a59 100644
--- a/lib/App/Raps2/UI.pm
+++ b/lib/App/Raps2/UI.pm
@@ -89,15 +89,17 @@ sub read_pw {
}
sub to_clipboard {
- my ( $self, $str ) = @_;
+ my ( $self, $str, $cmd ) = @_;
+
+ $cmd //= 'xclip -l 1';
- open( my $clipboard, q{|-}, 'xclip -l 1' )
+ open( my $clipboard, q{|-}, $cmd )
or return;
print $clipboard $str;
close($clipboard)
- or cluck("Failed to close pipe to xclip: $!");
+ or cluck("Failed to close pipe to ${cmd}: ${!}");
return 1;
}
@@ -172,9 +174,10 @@ Prompt the user for a password. I<message> is displayed, the user's input is
noch echoed. If I<verify> is set, the user has to enter the same input twice,
otherwise B<read_pw> dies. Returns the input.
-=item $ui->to_clipboard(I<$string>)
+=item $ui->to_clipboard(I<$string>, [I<command>])
-Place I<string> in the primary X Clipboard (by calling the B<xclip> program)
+Call I<command> to place I<string> in the primary X Clipboard. I<command>
+defaults to C<< xclip -l 1 >>.
Returns true upon success, undef if the operation failed. Use $! to get the
error message.