summaryrefslogtreecommitdiff
path: root/shroud
diff options
context:
space:
mode:
Diffstat (limited to 'shroud')
-rw-r--r--shroud/config.scm.in (renamed from shroud/config.scm)7
-rw-r--r--shroud/ui/show.scm51
-rw-r--r--shroud/utils.scm6
3 files changed, 45 insertions, 19 deletions
diff --git a/shroud/config.scm b/shroud/config.scm.in
index 803a3ac..00d6f39 100644
--- a/shroud/config.scm
+++ b/shroud/config.scm.in
@@ -1,3 +1,5 @@
+;;; -*- scheme -*-
+;;;
;;; Shroud
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;;
@@ -15,6 +17,9 @@
;;; along with Shroud. If not, see <http://www.gnu.org/licenses/>.
(define-module (shroud config)
- #:export (%shroud-version))
+ #:export (%shroud-version
+ %xclip))
(define %shroud-version "0.1")
+
+(define %xclip "@XCLIP@")
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))
diff --git a/shroud/utils.scm b/shroud/utils.scm
index 3f28840..58695e4 100644
--- a/shroud/utils.scm
+++ b/shroud/utils.scm
@@ -20,6 +20,7 @@
#:use-module (ice-9 rdelim)
#:use-module (ice-9 vlist)
#:use-module (srfi srfi-1)
+ #:use-module (shroud config)
#:export (vhash-ref
vhash-replace
vhash-values
@@ -28,6 +29,7 @@
gpg-binary
call-with-encrypted-output-file
call-with-decrypted-input-file
+ call-with-clipboard
mkdir-p))
(define (vhash-ref vhash key)
@@ -115,6 +117,10 @@ FILE."
"--decrypt" ,file)
proc)))))
+(define (call-with-clipboard proc)
+ "Call PROC with an open output port to the X clipboard."
+ (call-with-output-pipe* (list %xclip "-selection" "clipboard") proc))
+
;; Written by Ludovic Courtès for GNU Guix.
(define (mkdir-p dir)
"Create directory DIR and all its ancestors."