com

command module
v0.0.0-...-253f420 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2025 License: GPL-3.0 Imports: 11 Imported by: 0

README

com

Com is a go port of Tom Duff's com program. It is a simple build tool, very handy for single file programs, since you can embed the build instructions in the source code as comments.

Usage

Check com -h.

usage: com <file>...

Com searches through each file named on the command line for the
anchor string /*% or //% or @@% and takes the rest of the line to
be a Unix shell command, which it runs after substituting the
file name for any % characters, and the stem
(the file name minus the last. and any subsequent characters)
for any #'s. For example, if the file junk.c contains the comment

//% cc -o # % -lm -lmalloc

then com junk.c will run cc -o junk junk.c -lm -lmalloc.

Com stashes its argument list in a file called .comfile, so after
running it once, typing com with no arguments will recompile. To
include a literal % or # in the command, write %% or ##.

Flags:
  -a	append new commands to .comfile rather than overwrite it
  -f	fail fast, stop immediately if one command fails
  -n	dry run, print out actions, but not act
  -s	silent, do not print commands before execution
  -sh string
    	shell to use: sh -c <cmd> (default "/bin/sh")

Install

It needs go and has no other dependencies. Just

go install github.com/anastasop/com@latest

Discussion

Com is handy but did not make it to unix or plan9. It was however used internally in Bell Labs as you can see in the source code for the tenth edition. See apply and coreid among others.

Adding build instructions in the source is not good practice in the modern era of build tools but works. For example in early go versions, the test suite was written using this technique, see this commit. Files had comments like // $G $F.go && $L $F.$A && ./$A.out and a separate shell program called run build the shell command from the comments and run the test. Eventually this was replaced by a perl tool, prettier syntax and finally with the go tool.

License

Released under the GPLv3.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL