Programming languages


Carapace is a microframework for making your own command shell in C++. It's strictly string-oriented, with a shell-like syntax and variable support, but otherwise very barebones. That's deliberate: Carapace is meant for use cases where embedding a full-blown scripting language would be overkill.

Carapace targets C++11 and comes as a single header file. An optional second header adds a set of default commands inspired by Tcl, though they're of little use by themselves. See prompt.cpp for how to add your own.

For a pure C solution, check out the GeekFactory Shell Library. It's very similar in concept.

Sample session

This is what a typical interaction with Carapace will look like:

[felix@localhost carapace]$ ./prompt 
Carapace version 2018-05-18, with 26 commands.

> set greeting Welcome,
> eval 'puts "Hi! What is your name?"' 'puts "$greeting `gets`"'   
Hi! What is your name?
Welcome, Felix


The above illustrates most features of the framework. The default commands, should you decide to use them, know a few tricks as well.


May 2018 release (7.5k)

Carapace is open source under the MIT License. See the source code for details.

As of 18 May 2018, the parser still needs work. In particular, there's no way to escape a dollar sign during variable substitution, or for that matter any of the quoting characters. Test coverage is also lacking. Beware of bugs!


The default command set treats an empty string as false and any other as true; predicates return "t" for true, similar to Lisp. The framework however doesn't care at all; use whatever convention suits you.

Also about that, crabmeat.h makes a point of not including any other header than carapace.h, so only implements features supported by the same standard libraries as the framework proper.