{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreidwmpil4olwknuws2tuctycieyjaxc6uhhwncjtywsdtddh6mhyn4",
"uri": "at://did:plc:25rdn5elo5izoxrmtis34zuk/app.bsky.feed.post/3mogqzfvvdrh2"
},
"coverImage": {
"$type": "blob",
"ref": {
"$link": "bafkreif7skfa64ybjiirg3khwoy4gjdasu4nyizufagynlclhw5vlze6lq"
},
"mimeType": "image/webp",
"size": 6834
},
"path": "/ragnarokkr/commentor-evolution-of-my-comment-divider-73p",
"publishedAt": "2026-06-16T21:24:57.000Z",
"site": "https://dev.to",
"tags": [
"cli",
"tools",
"programming",
"odin",
"few months ago",
"Codeberg",
"Odin compiler"
],
"textContent": "A few months ago, I wrote a small Nushell script designed to take user-provided text and generate comments formatted for various programming languages.\n\nAfter using it for a while, a few flaws naturally emerged:\n\n * **Limited availability:** Being written as a Nushell command restricted its use to those who run this (otherwise great) shell.\n * **Performance:** Although Nushell performs well overall, heavy text processing isn't its primary strength.\n * **General limitations:** The script had a restricted set of styles, fixed layouts, and lacked support for custom borders or margins.\n\n\n\nTo overcome these limitations - and because I wanted to learn a new programming language - I decided to rewrite the project from scratch in Odin.\n\nPorting the tool to Odin was a great learning experience, even if I only scratched the surface 😅.\n\nAlthough this new version is still in its early stages and has room for improvement, it is already quite stable and reliable for daily use.\n\n## The Program\n\n**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.\n\nThe syntax is simple:\n\n\n\n echo <text> | commentor [flags]\n\n\nFor example, to generate an 80-character-wide block comment for a C-style language with centered, filled text, you can run:\n\n\n\n echo \"Hello World\" | commentor -language=c -style=block -width=80 -margin-css=0,1 -text-align=center -text-filler=- -text-padding=1\n\n\nWhich produces:\n\n\n\n /* ------------------------------ Hello World ------------------------------- */\n\n\nYou can also define custom padding, margins, and borders!\n\n\n\n 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\n\n\n\n\n /* ╭────────────────────────────────────────────────────────────────────────╮ */\n /* │ ---------------------------------------------------------------------- │ */\n /* │ ---------------------------------------------------------------------- │ */\n /* │ ---------------------------------------------------------------------- │ */\n /* │ ---------------------------- Hello World ----------------------------- │ */\n /* │ ---------------------------------------------------------------------- │ */\n /* │ ---------------------------------------------------------------------- │ */\n /* │ ---------------------------------------------------------------------- │ */\n /* ╰────────────────────────────────────────────────────────────────────────╯ */\n\n\n\n\n> **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!\n\nTo see all available options and flags, run:\n\n\n\n commentor -h\n\n\n\n Usage:\n commentor\n Flags:\n -border:<string>=<string> | sets a predefined border style or customize it.\n -divider | generates a comment divider.\n -language:<string> | identifier for the language style.\n -list:<string> | prints a list. [Possible values: alignments, border-styles, languages, styles]\n -margin:<string>=<uint> | comment margin.\n -margin-css:<string> | comment margins as CSS-like shorthand.\n -newline | should put the comment tokens on separate line?\n -no-indent | do not indent block comments.\n -padding:<string>=<uint> | comment padding.\n -padding-css:<string> | comment paddings as CSS-like shorthand.\n -style:<string> | style to be used for the comment. [Default 'inline']\n -text-align:<string> | alignment for the text inside the comment. [Default 'left']\n -text-filler:<rune> | character to use as filler text margins. [Default ' ']\n -text-padding:<string>=<uint> | text padding.\n -text-padding-css:<string> | text paddings as CSS-like shorthand.\n -version | prints the version of this program.\n -width:<uint> | maximum width for the comment. [Default 80]\n\n\nBy default, the utility tries to auto-detect the comment width, falling back to 80 characters if it cannot.\n\nStyles and languages are fully customizable via a JSON configuration file generated automatically on its first run.\n\n### IDE Support\n\nDue to its classic command-line nature, it is incredibly easy to integrate Commentor into your daily workflow.\n\nSince 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.\n\n#### 1. Define Tasks in Zed\n\nOpen the command palette and select `zed: open tasks`. Add the following task (this example uses Nushell; adapt the shell configuration as needed):\n\n\n\n {\n \"label\": \"Commentor - Header - Single Line\",\n \"command\": \"r#'$ZED_SELECTED_TEXT'# | commentor -language=\\\"$ZED_LANGUAGE\\\" -width=79 -border:style=text | wl-copy\",\n \"use_new_terminal\": true,\n \"reveal\": \"no_focus\",\n \"hide\": \"on_success\",\n \"shell\": {\n \"with_arguments\": {\n \"program\": \"nu\",\n \"args\": [\n \"--no-std-lib\",\n \"--env-config\",\n \"~/.config/nushell/env.nu\",\n \"-c\"\n ]\n }\n }\n }\n\n\n#### 2. Configure Keybindings in Zed\n\nOpen the command palette and select `zed: open keymap file`. Add keybindings to trigger your tasks:\n\n\n\n {\n \"context\": \"Editor && mode == full\",\n \"bindings\": {\n \"ctrl-1\": [\n \"task::Spawn\",\n { \"task_name\": \"Commentor - Header - Single Line\" }\n ]\n // ...\n }\n }\n\n\n## How to Build\n\nThe project is currently only distributed in source-code form. You can find the repository on Codeberg.\n\nTo build and install Commentor on your system, clone the repository and use the built-in task runner `norn` (written in Odin 😁):\n\n\n\n git clone https://codeberg.org/Ragnarokkr/commentor.git\n cd commentor\n\n odin run norn -- build debug # for testing\n odin run norn -- build release # for production\n odin run norn -- install <dest_path> # to install the optimized executable to a custom path\n\n\n> Make sure you have the Odin compiler installed and available in your system's `PATH`.\n\nThat's All Folks!! 🎉",
"title": "Commentor: evolution of my Comment Divider"
}