8000 Added -clip flag to send code to clipboard by samdfonseca · Pull Request #5 · rsc/2fa · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Added -clip flag to send code to clipboard #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import (
"strings"
"time"
"unicode"

"github.com/atotto/clipboard"
)

var (
Expand All @@ -86,13 +88,14 @@ var (
flagHotp = flag.Bool("hotp", false, "add key as HOTP (counter-based) key")
flag7 = flag.Bool("7", false, "generate 7-digit code")
flag8 = flag.Bool("8", false, "generate 8-digit code")
flagClip = flag.Bool("clip", false, "copy code to the clipboard")
)

func usage() {
fmt.Fprintf(os.Stderr, "usage:\n")
fmt.Fprintf(os.Stderr, "\t2fa -add [-7] [-8] [-hotp] keyname\n")
fmt.Fprintf(os.Stderr, "\t2fa -list\n")
fmt.Fprintf(os.Stderr, "\t2fa keyname\n")
fmt.Fprintf(os.Stderr, "\t2fa [-clip] keyname\n")
os.Exit(2)
}

Expand Down Expand Up @@ -126,7 +129,7 @@ func main() {
k.add(name)
return
}
k.show(name)
k.show(name, *flagClip)
}

type Keychain struct {
Expand Down Expand Up @@ -285,8 +288,12 @@ func (c *Keychain) code(name string) string {
return fmt.Sprintf("%0*d", k.digits, code)
}

func (c *Keychain) show(name string) {
fmt.Printf("%s\n", c.code(name))
func (c *Keychain) show(name string, clip bool) {
code := c.code(name)
if clip {
clipboard.WriteAll(code)
}
fmt.Printf("%s\n", code)
}

func (c *Keychain) showAll() {
Expand Down
27 changes: 27 additions & 0 deletions vendor/github.com/atotto/clipboard/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/atotto/clipboard/clipboard.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 52 additions & 0 deletions vendor/github.com/atotto/clipboard/clipboard_darwin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 98 additions & 0 deletions vendor/github.com/atotto/clipboard/clipboard_unix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions vendor/github.com/atotto/clipboard/clipboard_windows.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0