#!/usr/bin/env ruby oplop_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(oplop_dir) unless $LOAD_PATH.include?(oplop_dir) require 'oplop' require 'oplop/cli' require 'highline/import' require 'optparse' # -- exit nicely if control-c Signal.trap("SIGINT") { exit 2 } # -- options options = {} optparse = OptionParser.new do |opts| opts.banner = Oplop::Cli.banner options[:verbose] = false opts.on( '-v', '--verbose', 'Output the password to STDOUT' ) do options[:verbose] = true end options[:new] = false opts.on( '-n', '--new', 'New mode (2 prompt for master)') do options[:new] = true end opts.on( '-h', '--help', 'Display this screen' ) do puts opts puts "\n" puts Oplop::Cli.help exit end end.parse! # -- program label = ARGV.shift if label.nil? or label.empty? puts "!! You need to pass in a label!" exit 2 end master = ask("Enter your master password: ") { |q| q.echo = "*" } if options[:new] master_confirm = ask("Enter your master password (again): ") { |q| q.echo = "*" } if (master != master_confirm) puts "!! Your master and confirm don't match!" exit 2 end end password = Oplop::V1.password(:label => label, :master => master, :length => Oplop::V1::LEGACY_LENGTH) if options[:verbose] puts "\n Password for #{label}:\t#{password}\n\n" end if Oplop::Cli.copy_to_clipboard(password) print "Your #{label} password has been copied to your clipboard. \n" else print "!! Could not copy to clipboard, try installing xclip. " print "Run with --verbose flag to see password on STDOUT." unless options[:verbose] print "\n" end