summaryrefslogtreecommitdiff
path: root/com/simatime/caplinks.scm
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2019-11-01 14:24:24 -0700
committerBen Sima <ben@bsima.me>2019-11-01 14:25:49 -0700
commit9756eb0806aef63137ed53c7f78eee13aa3db9d7 (patch)
tree0c3bf0becc08e37386109ff8c518fa442df6266b /com/simatime/caplinks.scm
parent0a6fd40946f72e9995ca04b05d7556bf20585d4f (diff)
add buildHaskellApp nix function
Diffstat (limited to 'com/simatime/caplinks.scm')
-rwxr-xr-xcom/simatime/caplinks.scm45
1 files changed, 45 insertions, 0 deletions
diff --git a/com/simatime/caplinks.scm b/com/simatime/caplinks.scm
new file mode 100755
index 0000000..21f0b88
--- /dev/null
+++ b/com/simatime/caplinks.scm
@@ -0,0 +1,45 @@
+
+(define-module (com simatime caplinks)
+ #:use-module ((ice-9 popen) #:prefix popen/)
+ #:use-module ((com simatime string) #:prefix string/)
+ #:use-module ((com simatime shell) #:prefix sh/)
+ #:export (main get-all-nodes make-symlink))
+
+;; given a root directory, walk the tree and get a list of all the files. Then,
+;; for each file, symlink a capitalized version
+(define (main args)
+ (let* ((root (cadr args))
+ (files (get-all-nodes root)))
+ (for-each (lambda (file)
+ (display file)
+ (move-file file (capitalize-file file)))
+ files)
+ (display root) (newline)
+ (display "done moving files") (newline)
+ (newline)))
+
+(define (get-all-nodes root)
+ (filter (lambda (s) (not (equal? "" s)))
+ (string-split (sh/stream
+ (format #f "find ~a -name '*.hs*'" root))
+ #\newline)))
+
+(define (capitalize-file file)
+ (string-join (map string/capitalize (string-split file #\/))
+ "/"))
+
+(define (butlast ls)
+ (let ((len (length ls)))
+ (list-head ls (- len 1))))
+
+(define (dir-for f)
+ (string-join
+ (butlast (string-split f #\/))
+ "/"))
+
+(define (move-file here there)
+ (display (format #f "~a -> ~a" here there))
+ (newline)
+ ;; make the directory tree for the link, if it doesn't already exist
+ (system (format #f "mkdir -p ~a" (dir-for there)))
+ (system (format #f "mv ~a ~a" here there)))