惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
B
Blog
罗磊的独立博客
GbyAI
GbyAI
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Security Blog
Microsoft Security Blog
宝玉的分享
宝玉的分享
The GitHub Blog
The GitHub Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
博客园 - 聂微东
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
Visual Studio Blog
MyScale Blog
MyScale Blog
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Commentor: evolution of my Comment Divider
Marco Trulla · 2026-06-17 · via DEV Community
Cover image for Commentor: evolution of my Comment Divider

Marco Trulla

A few months ago, I wrote a small Nushell script designed to take user-provided text and generate comments formatted for various programming languages.

After using it for a while, a few flaws naturally emerged:

  • Limited availability: Being written as a Nushell command restricted its use to those who run this (otherwise great) shell.
  • Performance: Although Nushell performs well overall, heavy text processing isn't its primary strength.
  • General limitations: The script had a restricted set of styles, fixed layouts, and lacked support for custom borders or margins.

To overcome these limitations - and because I wanted to learn a new programming language - I decided to rewrite the project from scratch in Odin.

Porting the tool to Odin was a great learning experience, even if I only scratched the surface 😅.

Although this new version is still in its early stages and has room for improvement, it is already quite stable and reliable for daily use.

The Program

Commentor (a portmanteau of Comment and Generator) is a lightweight command-line utility. It takes piped input from the user and generates a fully formatted comment block for a specified language, styled to your liking.

The syntax is simple:

echo <text> | commentor [flags]

For example, to generate an 80-character-wide block comment for a C-style language with centered, filled text, you can run:

echo "Hello World" | commentor -language=c -style=block -width=80 -margin-css=0,1 -text-align=center -text-filler=- -text-padding=1

Which produces:

/* ------------------------------ Hello World ------------------------------- */

You can also define custom padding, margins, and borders!

echo "Hello World" | commentor -language=c -style=inline-block -width=80 -margin-css=2,1 -padding-css=3,1 -text-align=center -text-filler=- -text-padding-css=1 -border:style=round



/* ╭────────────────────────────────────────────────────────────────────────╮ */
/* │ ---------------------------------------------------------------------- │ */
/* │ ---------------------------------------------------------------------- │ */
/* │ ---------------------------------------------------------------------- │ */
/* │ ---------------------------- Hello World ----------------------------- │ */
/* │ ---------------------------------------------------------------------- │ */
/* │ ---------------------------------------------------------------------- │ */
/* │ ---------------------------------------------------------------------- │ */
/* ╰────────────────────────────────────────────────────────────────────────╯ */


Notice the CSS-like shorthand? Flags like -margin-css=2,1 allow you to set vertical and horizontal spacing using the familiar top/bottom, left/right shorthand syntax common in web design!

To see all available options and flags, run:

commentor -h

Usage:
        commentor
Flags:
        -border:<string>=<string>      | sets a predefined border style or customize it.
        -divider                       | generates a comment divider.
        -language:<string>             | identifier for the language style.
        -list:<string>                 | prints a list. [Possible values: alignments, border-styles, languages, styles]
        -margin:<string>=<uint>        | comment margin.
        -margin-css:<string>           | comment margins as CSS-like shorthand.
        -newline                       | should put the comment tokens on separate line?
        -no-indent                     | do not indent block comments.
        -padding:<string>=<uint>       | comment padding.
        -padding-css:<string>          | comment paddings as CSS-like shorthand.
        -style:<string>                | style to be used for the comment. [Default 'inline']
        -text-align:<string>           | alignment for the text inside the comment. [Default 'left']
        -text-filler:<rune>            | character to use as filler text margins. [Default ' ']
        -text-padding:<string>=<uint>  | text padding.
        -text-padding-css:<string>     | text paddings as CSS-like shorthand.
        -version                       | prints the version of this program.
        -width:<uint>                  | maximum width for the comment. [Default 80]

By default, the utility tries to auto-detect the comment width, falling back to 80 characters if it cannot.

Styles and languages are fully customizable via a JSON configuration file generated automatically on its first run.

IDE Support

Due to its classic command-line nature, it is incredibly easy to integrate Commentor into your daily workflow.

Since I do most of my development in the Zed editor, I have included an integration example below. However, any editor or IDE with a task system should run it with minimal effort.

1. Define Tasks in Zed

Open the command palette and select zed: open tasks. Add the following task (this example uses Nushell; adapt the shell configuration as needed):

{
    "label": "Commentor - Header - Single Line",
    "command": "r#'$ZED_SELECTED_TEXT'# | commentor -language=\"$ZED_LANGUAGE\" -width=79 -border:style=text | wl-copy",
    "use_new_terminal": true,
    "reveal": "no_focus",
    "hide": "on_success",
    "shell": {
        "with_arguments": {
            "program": "nu",
            "args": [
                "--no-std-lib",
                "--env-config",
                "~/.config/nushell/env.nu",
                "-c"
            ]
        }
    }
}

2. Configure Keybindings in Zed

Open the command palette and select zed: open keymap file. Add keybindings to trigger your tasks:

{
    "context": "Editor && mode == full",
    "bindings": {
        "ctrl-1": [
            "task::Spawn",
            { "task_name": "Commentor - Header - Single Line" }
        ]
        // ...
    }
}

How to Build

The project is currently only distributed in source-code form. You can find the repository on Codeberg.

To build and install Commentor on your system, clone the repository and use the built-in task runner norn (written in Odin 😁):

git clone https://codeberg.org/Ragnarokkr/commentor.git
cd commentor

odin run norn -- build debug          # for testing
odin run norn -- build release        # for production
odin run norn -- install <dest_path>  # to install the optimized executable to a custom path

Make sure you have the Odin compiler installed and available in your system's PATH.

That's All Folks!! 🎉