Skip to content

Instantly share code, notes, and snippets.

@danlentz
Created September 16, 2013 18:47
Show Gist options
  • Save danlentz/6584780 to your computer and use it in GitHub Desktop.
Save danlentz/6584780 to your computer and use it in GitHub Desktop.
tpapp SBCL script example
#!/usr/local/bin/sbcl --script
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
(ql:quickload "cl-fad" :verbose nil :explain nil :prompt nil)
(destructuring-bind (header footer &rest files)
(loop for arg in (cdr sb-ext:*posix-argv*)
collect (merge-pathnames arg *default-pathname-defaults*))
(format t "Header from: ~a~%" (enough-namestring header))
(format t "Footer from: ~a~%" (enough-namestring footer))
(loop for file in files
do (let* ((target (merge-pathnames file (make-pathname :type "org"))))
(format t "header + ~a + footer => ~a"
(enough-namestring file)
(enough-namestring target))
(with-open-file (stream target
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(flet ((append-to-target (filespec)
(with-open-file (source filespec :direction :input)
(cl-fad:copy-stream source stream))))
(append-to-target header)
(append-to-target file)
(append-to-target footer))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment