summaryrefslogtreecommitdiffstats
path: root/git-difme.scm
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2016-07-10 02:29:41 +0000
committerrsiddharth <s@ricketyspace.net>2016-07-10 02:29:41 +0000
commit140332256f2059be7b3a0fdcf082c3bb1f568df4 (patch)
tree33cd9f6ac6f3c79f89b90179f4de08f8b741afa5 /git-difme.scm
parent7eb853028f29303514c4d6f8b1780138a0b049df (diff)
add utility functions.
* git-difme.scm (with-directory-excursion): new macro. verbatim from (guix build utils). thank you ludovic courtès. (difme-exec): new function.
Diffstat (limited to 'git-difme.scm')
-rw-r--r--git-difme.scm30
1 files changed, 29 insertions, 1 deletions
diff --git a/git-difme.scm b/git-difme.scm
index e5d509a..76c35e2 100644
--- a/git-difme.scm
+++ b/git-difme.scm
@@ -2,6 +2,34 @@
;; license: gnu gpl version 3 or higher.
;; copyright 2016 rsiddharth <s@ricketyspace.net>
-;; main function.
+(define-module (git-difme)
+ #:use-module (ice-9 popen)
+ #:use-module (ice-9 rdelim)
+ #:export (main))
+
+;;;; utils
+
+;;; following macro from (guix build utils) module.
+;;; copyright 2012 Ludovic Courtès <ludo@gnu.org>
+;;; commit b0e0d0e99f
+
+(define-syntax-rule (with-directory-excursion dir body ...)
+ "run BODY with DIR as the process's current directory."
+ (let ((init (getcwd)))
+ (dynamic-wind
+ (lambda () (chdir dir))
+ (lambda () body ...)
+ (lambda () (chdir init)))))
+
+(define (difme-exec cmd)
+ "execute CMD and return output as a list of strings."
+ (let* ((port (open-input-pipe cmd))
+ (out (read-string port))
+ (out-lst (map string-trim-both
+ (delete "" (string-split out #\newline)))))
+ (close-pipe port)
+ out-lst))
+
+;;;; main
(define (main srcs)
srcs)