From 73312b933ffaf182a66a0176e1643099679f5208 Mon Sep 17 00:00:00 2001 From: Adrien Waksberg Date: Thu, 20 Oct 2016 13:49:17 +0200 Subject: [PATCH] copy: disable clipboard option --- bin/mpw-copy | 7 ++++++- lib/mpw/cli.rb | 38 ++++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/bin/mpw-copy b/bin/mpw-copy index c49d361..b4d770c 100644 --- a/bin/mpw-copy +++ b/bin/mpw-copy @@ -25,6 +25,7 @@ require 'mpw/cli' # --------------------------------------------------------- # options = {} +options[:clipboard] = true OptionParser.new do |opts| opts.banner = "#{I18n.t('option.usage')}: mpw copy [options]" @@ -33,6 +34,10 @@ OptionParser.new do |opts| options[:config] = config end + opts.on('-d', '--disable-clipboard', I18n.t('option.clipboard')) do + options[:clipboard] = false + end + opts.on('-g', '--group NAME', I18n.t('option.group')) do |group| options[:group] = group end @@ -60,4 +65,4 @@ opts = { search: options[:pattern], cli.get_wallet(options[:wallet]) cli.decrypt -cli.copy(opts) +cli.copy(options[:clipboard], opts) diff --git a/lib/mpw/cli.rb b/lib/mpw/cli.rb index 3779148..617b58d 100644 --- a/lib/mpw/cli.rb +++ b/lib/mpw/cli.rb @@ -287,7 +287,8 @@ class Cli # Copy in clipboard the login and password # @args: item -> the item - def clipboard(item) + # clipboard -> enable clipboard + def clipboard(item, clipboard=true) pid = nil # Security: force quit after 90s @@ -304,21 +305,33 @@ class Cli break when 'l', 'login' - Clipboard.copy(item.user) - puts I18n.t('form.clipboard.login').green + if clipboard + Clipboard.copy(item.user) + puts I18n.t('form.clipboard.login').green + else + puts item.user + end when 'p', 'password' - Clipboard.copy(@mpw.get_password(item.id)) - puts I18n.t('form.clipboard.password').yellow + if clipboard + Clipboard.copy(@mpw.get_password(item.id)) + puts I18n.t('form.clipboard.password').yellow - Thread.new do - sleep 30 + Thread.new do + sleep 30 - Clipboard.clear + Clipboard.clear + end + else + puts @mpw.get_password(item.id) end when 'o', 'otp' - Clipboard.copy(@mpw.get_otp_code(item.id)) + if clipboard + Clipboard.copy(@mpw.get_otp_code(item.id)) + else + puts @mpw.get_otp_code(item.id) + end puts I18n.t('form.clipboard.otp', time: @mpw.get_otp_remaining_time).yellow else @@ -490,8 +503,9 @@ class Cli end # Copy a password, otp, login - # @args: options -> the option to search - def copy(options={}) + # @args: clipboard -> enable clipboard + # options -> the option to search + def copy(clipboard=true, options={}) items = @mpw.list(options) if items.length == 0 @@ -500,7 +514,7 @@ class Cli table(items) item = get_item(items) - clipboard(item) + clipboard(item, clipboard) end rescue Exception => e puts "#{I18n.t('display.error')} #14: #{e}".red