{"id":22062555,"url":"https://github.com/pmiddend/cppshell","last_synced_at":"2026-04-28T20:38:10.107Z","repository":{"id":3707780,"uuid":"4779347","full_name":"pmiddend/cppshell","owner":"pmiddend","description":"Provide process handling and utilities like a shell for C++11","archived":false,"fork":false,"pushed_at":"2012-06-26T20:37:11.000Z","size":184,"stargazers_count":1,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-15T00:51:34.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pmiddend.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-25T08:12:47.000Z","updated_at":"2014-06-04T15:43:13.000Z","dependencies_parsed_at":"2022-09-01T07:52:33.710Z","dependency_job_id":null,"html_url":"https://github.com/pmiddend/cppshell","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmiddend%2Fcppshell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmiddend%2Fcppshell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmiddend%2Fcppshell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pmiddend%2Fcppshell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pmiddend","download_url":"https://codeload.github.com/pmiddend/cppshell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245143968,"owners_count":20568049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-30T18:21:21.121Z","updated_at":"2026-04-28T20:38:05.067Z","avatar_url":"https://github.com/pmiddend.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"cppshell\n===================\n\ncppshell, seriously?\n-----------\n\nYeah, it sounds strange, I know. Let me motivate it a bit.\n\nShell languages have traditionally been designed with the following in mind:\n\n- They're languages for both the command line prompt as well as scripts.\n- They have to be *short* so you don't have to type as much in the command line.\n- Being short usually means there are no *types*, so no *type safety* either.\n- Also, no *complex data structures*. You've got numbers, strings and arrays, mostly.\n- They're designed with certain \"shortcuts\" to operations you want to do very often. *Globbing* is an example of that (as in ls *.txt)\n- There are a lot of facilities for *pipes*, *redirection* and *process management*.\n\ncppshell, first of all, does *not* feature a command line. C++ is a language\nwhere you have to type a lot. Also, it's usually compiled, which takes some\ntime, so it's just not an ideal candidate for an interpreter.\n\nHowever, C++'s type safety and the RAII paradigm, as well as operator\noverloading, does play well with certain aspects of shell programming. For\nexample, let's say we want to\n\n- create a temporary file\n- write to it\n- pass it to a different program\n- delete it\n\nWith bash, you could accomplish this using something like:\n\n\tfilename=$(mkstemp)\n\techo \"lol\" \u003e $filename\n\tprogram $filename\n\trm $filename\n\nThis is fine, as long as `program` doesn't crash and as long as you don't\nforget the `rm` at the end. If either of the above happens, the temporary file\nstays in `/tmp`, and you might not even notice it: Programs that crash don't\ncrash the script.\n\nThe RAII solution in C++ would, of course, be a temporary file class that\ndeletes the file in the destructor (warning, this is pseudo-code for now):\n\n\tcppshell::temporary_file file;\n\tcppshell::write_string(file,\"lol\");\n\tcppshell::execute_program(\n\t\t\"program\",\n\t\tcppshell::program_arguments{\n\t\t\tfile.path()},\n\t\tcppshell::optional_input_fd{});\n\nIn the future, cppshell should wrap structures used for piping and process\nexecution, maybe even employing operator overloading, such as\n\n\tcppshell::execute_command(\n\t\t(cppshell::program(\"ls\",\"foo\") \u003c \"input_file.txt\")\n\t\t\t| cppshell::program(\"grep\",\"-r\",\"lol\"));\n\nIs it portable?\n---------------\n\nCurrently, it needs POSIX and Linux, mostly out of laziness.\n\nWhat are the dependencies\n-------------------------\n\nA recent compiler (either gcc or clang), boost and fcppt.\n\nWhy C++11?\n----------\n\nBecause it's well-supported on Linux and because I wanted to play with it.\n\nWhat's this \"fcppt\" dependency, do you really need it?\n------------------------------------------------------\n\nfcppt is a valuable addition to C++11 and boost, featuring, amongst others,\nstrong typedefs. It's extremely portable and easy to install, so it shouldn't\nbe a problem.\n\nDocumentation\n========\n\nUsing the \"jit\"\n---------------\n\nIn bash, you can write script files just like normal text files, but with a\n\"shebang\" line at the top, as such:\n\n\t#!/bin/bash\n\n\techo \"my script\"\n\nThis is possible in cppshell, too, using the same syntax. Assuming the program\n`cppshell_jit` is in your `$PATH`:\n\n\t#!/usr/bin/env cppshell_jit\n\t#include \u003ciostream\u003e\n\n\tint main()\n\t{\n\t\tstd::cout \u003c\u003c \"my script\\n\";\n\t}\n\nYou could store this file as `test.cpp` and give it executable permissions (via\n`chmod +x test.cpp`) and it's runnable.\n\ncppshell will read the configuration file to determine the compiler of your\nchoice (if no configuration exists, it will look for g++ in your `$PATH`) and\ncompile the file. If errors occur, those will be printed. If no errors occur,\nthe program will be executed. The configuration file resides in\n`$XDG_CONFIG_HOME/cppshell/config.ini` and has a very simple format. Set your\npreferred compiler using:\n\n\tcompiler=/usr/bin/clang++\n\nArguments can be passed to the script. They will be forwarded to the script as\narguments to `main`:\n\n\t#!/usr/bin/env cppshell_jit\n\t#include \u003ciostream\u003e\n\n\tint main(\n\t\tint argc,\n\t\tchar *argv[])\n\t{\n\t\tstd::cout \u003c\u003c \"=\u003e Hi, \" \u003c\u003c argv[1] \u003c\u003c \"!\\n\";\n\t}\n\nWill result in:\n\n\t./test.cpp Philipp\n\t=\u003e Hi, Philipp!\n\nIf you need additional libraries or compilerflags in your script, you can pass\nthose to the cppshell_jit program, too:\n\n\t#!/usr/bin/env cppshell_jit -lSDL\n\t#include \u003ciostream\u003e\n\t#include \u003cSDL.h\u003e\n\n\tint main()\n\t{\n\t\tSDL_Init(SDL_INIT_VIDEO);\n\t}\n\n\nIn the future, there'll be a cache, so scripts will be compiled only once. This\nis not implemented, yet (see issue gh-1).\n\nAlso, default cflags and lflags should be configurable via configuration file\n(see issue gh-2).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmiddend%2Fcppshell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpmiddend%2Fcppshell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpmiddend%2Fcppshell/lists"}