Skip to content

rivethorn/newc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

newc

A tiny C command-line tool that scaffolds new C projects with a src/, include/, and CMake-based build setup. No manual directory juggling or boilerplate typing.

What it creates

Running newc <project-name> generates:

<project-name>/
├── CMakeLists.txt        # C11, warnings on, ASan+UBSan in debug builds
├── src/
│   └── main.c            # includes the matching header, prints a hello
├── include/
│   └── <project-name>.h  # header guard already set up
├── .gitignore            # ignores out/, compile_commands.json, *.o
└── out/                  # empty, ready for cmake's output (matches
                           # Neovim's cmake-tools plugin default)

Install

You can use the install.sh script to install newc on your system:

curl -fsSL https://raw.githubusercontent.com/rivethorn/newc/main/install.sh | bash

Build from source

First clone the repo:

git clone https://github.com/rivethorn/newc.git && cd newc

Then:

cmake -B out && cmake --build out
sudo cmake --install out

Or if you want to use make:

make install        # builds newc.c and installs to /usr/local/bin

Other Makefile targets:

Command What it does
make build Compiles newc.c into a local newc binary
make install Builds (if needed) and installs to $PREFIX/bin (default /usr/local)
make clean Removes the local newc binary
make uninstall Removes the installed binary

To install somewhere other than /usr/local:

make install PREFIX=$HOME/.local

Make sure the install location is on your PATH.

Usage

newc my-cool-app
cd my-cool-app
cmake -S . -B out
cmake --build out
./out/my-cool-app

Notes

  • Project names with hyphens or other non-alphanumeric characters are automatically sanitized into valid C header guards (e.g. password-vaultPASSWORD_VAULT_H).
  • CMakeLists.txt uses file(GLOB ...) to pick up source files, so adding new .c files to src/ later doesn't require editing the build config.
  • Re-running newc on a name that already exists will fail safely without overwriting anything.

License

MIT — see LICENSE.