Skip to content

Instantly share code, notes, and snippets.

@ebith
Last active October 10, 2015 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ebith/3767494 to your computer and use it in GitHub Desktop.
Save ebith/3767494 to your computer and use it in GitHub Desktop.
KeePass2のデータベースをターミナルから検索してクリップボードにコピーする
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use File::KeePass;
use IO::Prompter;
use Encode;
my $file = shift @ARGV;
my $pass = prompt('Password: ', -e => '');
my $k = File::KeePass->new;
$k->load_db($file, $pass);
$k->unlock;
my @entries = $k->find_entries({});
open(OUT, '| peco --initial-matcher Migemo | awk \'BEGIN { FS = " :: "} { printf $2 }\' | pbcopy ');
foreach my $entry (@entries) {
next unless ($entry->{password});
print OUT encode_utf8("$entry->{title} : $entry->{username} :: $entry->{password}\n");
}
close(OUT);
$k->clear;
__END__
curl -L https://cpanmin.us | perl - --sudo App::cpanminus
cpanm --sudo File::KeePass IO::Prompter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment