commit aefbcedc886d924a1941bb375de6fd1146420432 Author: Ezekiel Grave Date: Wed Dec 11 17:06:06 2019 -0800 A qubes-pass-client selection/paste UI diff --git a/qubes-gopass.go b/qubes-gopass.go new file mode 100644 index 0000000..e966222 --- /dev/null +++ b/qubes-gopass.go @@ -0,0 +1,73 @@ +package main + +import ( + "bytes" + "io" + "log" + "os" + "os/exec" +) + +func Execute(output_buffer *bytes.Buffer, stack ...*exec.Cmd) (err error) { + var error_buffer bytes.Buffer + pipe_stack := make([]*io.PipeWriter, len(stack)-1) + idx := 0 + for ; idx < len(stack)-1; idx++ { + stdin_pipe, stdout_pipe := io.Pipe() + stack[idx].Stdout = stdout_pipe + stack[idx].Stderr = &error_buffer + stack[idx+1].Stdin = stdin_pipe + pipe_stack[idx] = stdout_pipe + } + stack[idx].Stdout = output_buffer + stack[idx].Stderr = &error_buffer + + if err := call(stack, pipe_stack); err != nil { + log.Fatalln(error_buffer.String(), err) + } + return err +} + +func call(stack []*exec.Cmd, pipes []*io.PipeWriter) (err error) { + if stack[0].Process == nil { + if err = stack[0].Start(); err != nil { + return err + } + } + if len(stack) > 1 { + if err = stack[1].Start(); err != nil { + return err + } + defer func() { + if err == nil { + pipes[0].Close() + err = call(stack[1:], pipes[1:]) + } + }() + } + return stack[0].Wait() +} + +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() + //io.Copy(os.Stdout, &b1) + + 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"), + ); err != nil { + log.Fatalln(err) + } + b2.WriteString("pass paste complete") + io.Copy(os.Stdout, &b2) +}