summaryrefslogtreecommitdiff
path: root/shroud/ui/show.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-08-17 22:27:26 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-08-17 22:27:26 -0400
commit288969b63fa8492f741fe89ba194920b5efd0400 (patch)
tree4278439f4a53179535a50f04de7ac1f01085f1b5 /shroud/ui/show.scm
parent9b3a17e3817fb47b1414aa0480948cbbcc03ca16 (diff)
Add X clipboard support.
* configure.ac (XCLIP): New variable. * package.scm: Add xclip dependency. * shroud/config.scm: Untrack. Now automatically generated. * shroud/config.scm.in: New file. * shroud/utils.scm (call-with-clipboard): New procedure. * shroud/ui/show.scm (%options): Add --clipboard option. (show-help): Add help text for --clipboard. (display-secret): New procedure. (shroud-show): Handle --clipboard option.
Diffstat (limited to 'shroud/ui/show.scm')
-rw-r--r--shroud/ui/show.scm51
1 files changed, 33 insertions, 18 deletions
diff --git a/shroud/ui/show.scm b/shroud/ui/show.scm
index fd076eb..21a35e2 100644
--- a/shroud/ui/show.scm
+++ b/shroud/ui/show.scm
@@ -28,6 +28,8 @@
(format #t "Usage: shroud show [OPTION] ID [KEY ...]
Show secret named ID.~%")
(display "
+ -c, --clipboard copy output to the X clipboard")
+ (display "
-h, --help display this help and exit")
(display "
--version display version information and exit")
@@ -40,7 +42,10 @@ Show secret named ID.~%")
(exit 0)))
(option '("version") #f #f
(lambda args
- (show-version-and-exit)))))
+ (show-version-and-exit)))
+ (option '("clipboard" #\c) #f #f
+ (lambda (opt name arg result)
+ (alist-cons 'clipboard? #t result)))))
(define %default-options '())
@@ -54,28 +59,38 @@ Show secret named ID.~%")
(alist-cons 'id arg result)))
%default-options))
+(define* (display-secret secret keys #:optional (port (current-output-port)))
+ (match keys
+ (()
+ (for-each (match-lambda
+ ((key . value)
+ (format port "~a\t~a~%" key value)))
+ (secret-contents secret)))
+ ((keys ...)
+ (for-each (match-lambda
+ ((key . value)
+ (when (member key keys)
+ (format port "~a~%" value))))
+ (secret-contents secret)))))
+
(define (shroud-show config db . args)
- (let* ((opts (process-args args))
- (id (leave-if-false (assq-ref opts 'id)
- "no secret ID given"))
- (keys (alist-pick opts 'key))
- (secret (vhash-ref (secrets-by-id (force db)) id)))
+ (let* ((opts (process-args args))
+ (id (leave-if-false (assq-ref opts 'id)
+ "no secret ID given"))
+ (keys (alist-pick opts 'key))
+ (clipboard? (assq-ref opts 'clipboard?))
+ (secret (vhash-ref (secrets-by-id (force db)) id)))
(unless secret
(leave "secret '~a' does not exist" id))
- (match keys
- (()
- (for-each (match-lambda
- ((key . value)
- (format #t "~a\t~a~%" key value)))
- (secret-contents secret)))
- ((keys ...)
- (for-each (match-lambda
- ((key . value)
- (when (member key keys)
- (format #t "~a~%" value))))
- (secret-contents secret))))
+ (if clipboard?
+ (call-with-clipboard
+ (lambda (port)
+ (display-secret secret keys port)
+ (display "copied secret to clipboard\n"
+ (current-error-port))))
+ (display-secret secret keys))
;; Database remains unaltered.
db))