aboutsummaryrefslogtreecommitdiff
path: root/twofa
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2019-12-19 09:44:27 +0000
committerNat Lasseter <user@4574.co.uk>2019-12-19 09:44:27 +0000
commit16f7d3f1e3ef999c9515b93f0525d0e2db215633 (patch)
tree04b644ff8b217051f7b81840ee2f770c35cb8bd9 /twofa
parent9529d2a2807f1c7a2c100d3de39e6e9e9c6b3b0d (diff)
Added cli options and clipboard copying
Diffstat (limited to 'twofa')
-rwxr-xr-xtwofa31
1 files changed, 28 insertions, 3 deletions
diff --git a/twofa b/twofa
index 01c6e0c..a63c37f 100755
--- a/twofa
+++ b/twofa
@@ -2,6 +2,7 @@
require "openssl"
require "base32"
+require "optimist"
def db32(str)
Base32.decode(str)
@@ -62,8 +63,24 @@ class Secrets
end
end
-TWOFAFILE = File.join(ENV["HOME"], ".twofa")
-fatal("No 2fa issuers file at ~/.twofa") unless File.exist?(TWOFAFILE)
+opts = Optimist::options do
+ version "twofa (c) 2019 Nat Lasseter"
+ banner <<-EOS
+twofa is a command line TOTP code generator.
+
+Usage:
+ twofa [opts] ISSUER
+
+where [opts] are:
+EOS
+
+ opt :no_clip, "Do not copy code to the clipboard"
+ opt :twofa_file, "Location of the twofa secrets file",
+ type: :string, default: File.join(ENV["HOME"], ".twofa")
+end
+
+TWOFAFILE = opts[:twofa_file]
+fatal("No 2fa issuers file at #{File.absolute_path(TWOFAFILE)}") unless File.exist?(TWOFAFILE)
SECRETS = Secrets.new(File.readlines(TWOFAFILE).map(&:strip))
@@ -73,4 +90,12 @@ fatal("Specify issuer") if ISSUER.nil?
sec = SECRETS[ISSUER]
fatal("No such issuer") if sec.nil?
-puts "#{sec.verify} (for #{sec.time_remaining} more seconds)"
+code = sec.verify
+time = sec.time_remaining
+puts "#{code} (for #{time} more seconds)"
+
+unless opts[:no_clip] then
+ require "clipboard"
+ Clipboard.copy(code)
+ puts "(Copied to clipboard)"
+end