Lambda Symbolics

CCLSH: a shell for the alien age

A system shell running inside a live Clozure Common Lisp image. Run ordinary Unix programs, evaluate Lisp at the same prompt, and reach for Lisp when a command string stops being the right tool.

Not a POSIX shell. Quite intentionally. Thanks, Sphere.

CCLSH · Properties
Runtime
Clozure Common Lisp 1.13
Interface
Unix commands and Common Lisp
Line editor
Clinedi
Package
reproducible Nix flake for Linux x86-64
Repository
luciusmagn/cclsh

Hybrid language composition

CCLSH is a shell that extends provides a new REPL for Clozure CL extended with shell facilities. A line. beginning with a parenthesis is evaluated as Common Lisp. Everything else resolves as a builtin or a program in PATH. Lisp values can become command arguments, and command output can come back to Lisp as data.

Note that CCLSH does not pretend that shell punctuation is a programming language; process composition is written as ordinary, beautiful, inspectable Lisp.

A live session
magnusi@lho-thinkpad (CCLSH-USER) ~/work $ git status --short
 M source/prompt.lisp
magnusi@lho-thinkpad (CCLSH-USER) ~/work $ (+ 20 22)
42
magnusi@lho-thinkpad (CCLSH-USER) ~/work $ echo branch: (capture (git "branch" "--show-current"))
branch: master
magnusi@lho-thinkpad (CCLSH-USER) ~/work $ ../
magnusi@lho-thinkpad (CCLSH-USER) ~ $

Process composition you can read

Pipelines, redirection, sequencing, and conditional execution are Lisp forms. A command defined in Lisp works from the command line and as a function in the same image.

Pipelines and status
(pipe (from "access.log")
      (grep "500")
      (wc "-l"))

(all (make "test")
     (make "install"))

(capture
  (git "rev-parse" "--short" "HEAD"))
A command that is also a function
(defcommand gs (&rest arguments)
  "Show a concise Git status."
  (apply #'run
         "git" "status" "--short"
         arguments))

gs
(gs)

Field notes

Interactive systems · Included surfaces
Line editing Unicode grapheme movement, completion, highlighting, persistent history, and inline suggestions through the grace of Clinedi.
Terminal work External commands and pipelines get foreground process groups, Ctrl-C, Ctrl-Z, and the usual jobs, fg, and bg controls.
Navigation Type an explicit directory path such as .., ./src, or ~/work to enter it directly. Shamelessly stolen from Fish shell.
Customization startup.lisp can define commands, environment policy, directory hooks, custom prompt or redefine anything about the shell, with some elbow grease.
Lisp systems The saved image includes Quicklisp and the pinned Clinedi revision, with writable package state outside the Nix store.

Try it with Nix

The packaged target supports Linux x86-64 and pins CCL, Clinedi, Quicklisp, and the required CCL kernel patches. Run it directly, or put it in your Nix profile.

Btw, CCLSH is its own command language, not a replacement for sh scripts. The Nix package install does not edit /etc/shells or change your login shell. Play with it first!

Installation · Nix flakes
Run without installing
$ nix run github:luciusmagn/cclsh

Install into your profile
$ nix profile install github:luciusmagn/cclsh

Source code here:
$ git clone https://github.com/luciusmagn/cclsh