From 2aae3e9091392e0c69298ed5e750ae02c7777e9f Mon Sep 17 00:00:00 2001 From: Ezekiel Grave Date: Sun, 19 Apr 2020 10:53:19 -0700 Subject: [PATCH] Allow first positional argument to be the password selection. --- qubes-gopass.go | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/qubes-gopass.go b/qubes-gopass.go index e495254..e235698 100644 --- a/qubes-gopass.go +++ b/qubes-gopass.go @@ -2,6 +2,8 @@ package main import ( "bytes" + "flag" + //"fmt" "io" "log" "os" @@ -49,22 +51,31 @@ func call(stack []*exec.Cmd, pipes []*io.PipeWriter) (err error) { } func main() { - var b1 bytes.Buffer - if err := Execute(&b1, - exec.Command("qubes-pass-client", "list", "-f"), - exec.Command("tail", "-n", "+2"), - exec.Command("zenity", "--list", "--title", "Select a Password", "--column", "Password"), - ); err != nil { - log.Fatalln(err) - } - selection := b1.String() + var selection string + flag.Parse() + switch specified := flag.Arg(0); specified { + case "": + //fmt.Printf("Specified: %q\n", specified) + var b1 bytes.Buffer + if err := Execute(&b1, + exec.Command("qubes-pass-client", "list", "-f"), + exec.Command("tail", "-n", "+2"), + exec.Command("zenity", "--list", "--width=666", "--height=999", "--title", "Select a Password", "--column", "Password"), + ); err != nil { + log.Fatalln(err) + } + selection = b1.String() //io.Copy(os.Stdout, &b1) + default: + //fmt.Printf("Specified: %q\n", specified) + selection = specified + } var b2 bytes.Buffer if err := Execute(&b2, exec.Command("qubes-pass-client", "show", selection), exec.Command("sed", "2q;d"), - exec.Command("timeout", "--preserve-status", "9", "xclip", "-quiet", "-loops", "1"), + exec.Command("timeout", "--preserve-status", "12", "xclip", "-quiet", "-loops", "1"), ); err != nil { log.Fatalln(err) }