mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
copy: disable clipboard option
This commit is contained in:
parent
f5746d6af6
commit
73312b933f
2 changed files with 32 additions and 13 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue