Skip to content

Instantly share code, notes, and snippets.

@KeenS
Last active December 13, 2016 07:13
Show Gist options
  • Save KeenS/6688683 to your computer and use it in GitHub Desktop.
Save KeenS/6688683 to your computer and use it in GitHub Desktop.
A function for shelly to load a file ignoring shebang. This is useful to write a script with Common Lisp.
(in-package :shelly)
(export (defvar *argv* nil))
(in-package :cl-user)
(defun script (file argv)
"Execute a file as script ignoring shebang"
(setf shelly:*argv* argv)
(let* ((in (open file :if-does-not-exist :error))
(first-char (read-char in))
(second-char (read-char in)))
(cond
((and (char= first-char #\#) (char= second-char #\!))
(read-line in))
(t (unread-char second-char in)
(unread-char first-char in)))
(load in)
(values)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment