Advertisement
Guest User

password script

a guest
Aug 16th, 2012
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.98 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4.  
  5. $|=1; ## Autoflush
  6.  
  7. my $first_pass;
  8. my $before = get_clipboard();
  9.  
  10. open my $in, 'gpg --no-tty -d ~/Dropbox/Passwords/passwords.gpg 2>/dev/null|' or die $!;
  11. while( <$in> ){
  12.     my $line = $_; $line =~ s/[\r\n]+//gsm;
  13.  
  14.     foreach my $arg ( @ARGV ){
  15.         if( $line =~ /\Q$arg\E/i ){
  16.             print "$line\n";
  17.  
  18.             if( !defined($first_pass) && $line =~ /(\S+)$/ ){
  19.                 set_clipboard( $1 );
  20.                 $first_pass = $1;
  21.             }
  22.  
  23.             last;
  24.         }
  25.     }
  26. }
  27.  
  28. ## Sleep 10 seconds then reset the clipboard
  29.     if( defined $first_pass ){
  30.         local $SIG{INT} = sub { reset_clipboard(); exit 1; };
  31.         sleep 10;
  32.         reset_clipboard();
  33.     }
  34.  
  35. sub reset_clipboard {
  36.     if( defined $first_pass && get_clipboard() eq $first_pass ){
  37.         set_clipboard( $before );
  38.     }
  39. }
  40.  
  41. sub set_clipboard {
  42.     open my $out, '| /usr/bin/xclip -selection clipboard -in' or die $!;
  43.     syswrite( $out, $_[0] );
  44.     close $out;
  45. }
  46.  
  47. sub get_clipboard {
  48.     return `/usr/bin/xclip -selection clipboard -out`;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement