@k2ksv/cpt-cli
v1.0.0
Published
Competitive Programming Terminal — scaffold, compile, and test C++ solutions instantly from your terminal.
Maintainers
Readme
⚡ cpt — Competitive Programming Terminal
Scaffold, compile, and test C++ solutions in seconds — right from your terminal.
cpt is a minimal, opinionated Zsh CLI that eliminates the repetitive boilerplate of competitive programming. One command to create a file, one to compile, one to run — with automatic input detection and customisable compiler flags.
✨ Features
- ⚡ Instant Scaffolding — Generate C++ files from a personal template (
~/.cpt_template.cpp) or a sensible built-in default. - 🔧 Smart Compilation — Compiles with competitive-programming-friendly flags out of the box (
-std=c++17 -Wall -Wextra -O2 -fsanitize=undefined). - 🎯 Automatic Input Detection — If
input.txtexists in the working directory it is piped into your solution automatically. - ⏱️ Built-in Timing — Every run is wrapped in
timeso you can spot TLE risks early. - 🎨 Colourful Output — Clear, colour-coded terminal messages so you never miss an error.
- 🛠️ Fully Configurable — Override compiler flags globally via
$CPT_CXXFLAGS.
📦 Installation
Via npm (recommended)
npm install -g cpt-cliThat's it — cpt is now available globally.
Via curl (one-liner)
sudo curl -fsSL https://raw.githubusercontent.com/k2ksv/CPT_CLI/main/cpt \
-o /usr/local/bin/cpt && sudo chmod +x /usr/local/bin/cptManual Install
git clone https://github.com/k2ksv/CPT_CLI.git
cd CPT_CLI
chmod +x cpt
sudo cp cpt /usr/local/bin/Template (optional but recommended)
Copy the included template to your home directory so cpt init uses it:
cp .cpt_template.cpp ~/.cpt_template.cpp⚙️ Configuration
cpt uses sensible defaults that work for most competitive programming judges. You can override the compiler flags by exporting CPT_CXXFLAGS in your shell config:
# ~/.zshrc (or ~/.bashrc)
export CPT_CXXFLAGS="-std=c++20 -O2 -DLOCAL"| Variable | Default | Description |
|---|---|---|
| CPT_CXXFLAGS | -std=c++17 -Wall -Wextra -O2 -fsanitize=undefined | Flags passed to g++ during compilation |
🚀 Usage
1. Create a new solution file
cpt init A.cppThis copies ~/.cpt_template.cpp into A.cpp. If no template is found, a minimal boilerplate is generated.
2. Compile
cpt build A.cppCompiles A.cpp → A using your configured (or default) flags.
3. Run
cpt run A.cpp- If
input.txtexists in the current directory →./A < input.txt - Otherwise → runs interactively so you can type input manually.
Full Workflow Example
cpt init B.cpp # scaffold
vim B.cpp # write your solution
echo "5" > input.txt # prepare sample input
cpt build B.cpp # compile
cpt run B.cpp # test against input.txt🗂️ Project Structure
CPT_CLI/
├── cpt # Main CLI script
├── .cpt_template.cpp # Sample C++ template
├── package.json # npm package manifest
├── README.md
└── LICENSE📄 License
This project is licensed under the MIT License.
