/shell-utility

Primary LanguageCommon LispOtherNOASSERTION

Shell utility

This library let’s you generate shell scripts from SBCL. Here’s how:

;; Any number of load, eval or load-system commands can be used.

(shell-utility:write-shell-utility :sbcl
  (:name "/home/username/bin/hello") ;; name of script
  (:load-system :alexandria)
  (:eval (defun hello (names &key (intensity "1"))
           (format t "Hello ~{~A~^ and ~}" names)
           (dotimes (n (read-from-string intensity))
             (princ "!"))
           (terpri)))
  (:launch hello)) ;; Call hello with error handler and parsed argv.

Evaluating the above form (fill in your username) will generate a shell script that looks like this:

#!/bin/sh
sbcl \
--noinform \
--disable-debugger \
--quit \
--eval '(ASDF:LOAD-SYSTEM "alexandria")' \
--eval '(DEFUN HELLO (NAMES &KEY (INTENSITY "1")) (FORMAT T "Hello ~{~A~^ and ~}" NAMES) (DOTIMES (N (READ-FROM-STRING INTENSITY)) (PRINC "!")) (TERPRI))' \
--eval '(ASDF:LOAD-SYSTEM "shell-utility")' \
--eval '(SHELL-UTILITY::LAUNCH/2 (QUOTE SHELL-UTILITY::SBCL) (QUOTE HELLO))' \
"$@"

The script can be run as follows:

hello --intensity 2 Homer Marge Bart Lisa Maggie

Other commands are available too, please see examples.lisp or study the source and tests.