mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-21 10:20:05 +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 = {}
|
||||||
|
options[:clipboard] = true
|
||||||
|
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
opts.banner = "#{I18n.t('option.usage')}: mpw copy [options]"
|
opts.banner = "#{I18n.t('option.usage')}: mpw copy [options]"
|
||||||
|
@ -33,6 +34,10 @@ OptionParser.new do |opts|
|
||||||
options[:config] = config
|
options[:config] = config
|
||||||
end
|
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|
|
opts.on('-g', '--group NAME', I18n.t('option.group')) do |group|
|
||||||
options[:group] = group
|
options[:group] = group
|
||||||
end
|
end
|
||||||
|
@ -60,4 +65,4 @@ opts = { search: options[:pattern],
|
||||||
|
|
||||||
cli.get_wallet(options[:wallet])
|
cli.get_wallet(options[:wallet])
|
||||||
cli.decrypt
|
cli.decrypt
|
||||||
cli.copy(opts)
|
cli.copy(options[:clipboard], opts)
|
||||||
|
|
|
@ -287,7 +287,8 @@ class Cli
|
||||||
|
|
||||||
# Copy in clipboard the login and password
|
# Copy in clipboard the login and password
|
||||||
# @args: item -> the item
|
# @args: item -> the item
|
||||||
def clipboard(item)
|
# clipboard -> enable clipboard
|
||||||
|
def clipboard(item, clipboard=true)
|
||||||
pid = nil
|
pid = nil
|
||||||
|
|
||||||
# Security: force quit after 90s
|
# Security: force quit after 90s
|
||||||
|
@ -304,21 +305,33 @@ class Cli
|
||||||
break
|
break
|
||||||
|
|
||||||
when 'l', 'login'
|
when 'l', 'login'
|
||||||
Clipboard.copy(item.user)
|
if clipboard
|
||||||
puts I18n.t('form.clipboard.login').green
|
Clipboard.copy(item.user)
|
||||||
|
puts I18n.t('form.clipboard.login').green
|
||||||
|
else
|
||||||
|
puts item.user
|
||||||
|
end
|
||||||
|
|
||||||
when 'p', 'password'
|
when 'p', 'password'
|
||||||
Clipboard.copy(@mpw.get_password(item.id))
|
if clipboard
|
||||||
puts I18n.t('form.clipboard.password').yellow
|
Clipboard.copy(@mpw.get_password(item.id))
|
||||||
|
puts I18n.t('form.clipboard.password').yellow
|
||||||
|
|
||||||
Thread.new do
|
Thread.new do
|
||||||
sleep 30
|
sleep 30
|
||||||
|
|
||||||
Clipboard.clear
|
Clipboard.clear
|
||||||
|
end
|
||||||
|
else
|
||||||
|
puts @mpw.get_password(item.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
when 'o', 'otp'
|
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
|
puts I18n.t('form.clipboard.otp', time: @mpw.get_otp_remaining_time).yellow
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -490,8 +503,9 @@ class Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
# Copy a password, otp, login
|
# Copy a password, otp, login
|
||||||
# @args: options -> the option to search
|
# @args: clipboard -> enable clipboard
|
||||||
def copy(options={})
|
# options -> the option to search
|
||||||
|
def copy(clipboard=true, options={})
|
||||||
items = @mpw.list(options)
|
items = @mpw.list(options)
|
||||||
|
|
||||||
if items.length == 0
|
if items.length == 0
|
||||||
|
@ -500,7 +514,7 @@ class Cli
|
||||||
table(items)
|
table(items)
|
||||||
|
|
||||||
item = get_item(items)
|
item = get_item(items)
|
||||||
clipboard(item)
|
clipboard(item, clipboard)
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
puts "#{I18n.t('display.error')} #14: #{e}".red
|
puts "#{I18n.t('display.error')} #14: #{e}".red
|
||||||
|
|
Loading…
Add table
Reference in a new issue