echo-comment
A bidirectional bash interpreter that converts between comments and echo statements, making your shell scripts cleaner and more maintainable.
The Problem
Ever written a shell script like this?
#!/usr/bin/env bash
||
The actual business logic is completely obscured by echo statements!
The Solution
Write your scripts with clean comments instead:
#!/usr/bin/env echo-comment
# ๐งน Cleaning up any existing .so files...
||
# ๐ Running pre-commit checks...
# ๐จ Building fresh release version...
# ๐ฆ Downloading wheel artifacts...
At runtime, echo-comment automatically converts comments to echo statements, so you get the verbose output without cluttering your source code.
To write a comment that doesn't get echoed, simply start the line with 2: ## ...
Demo
Here is our script hello.sh with 3 steps
- Python: We use Python to print "๐ Hiss" and "๐ฑ Meow" and grep the snake emoji
- Pause: Then we do a no-op using the bash
:operator - Echo Lastly we
echo "Goodbye"
# 1) Run some Python
|
# 2) Pause for effect...
# 3) Complete
bash
Run normally, you get Hiss and Goodbye:
โฃ
๐ Hiss
Goodbye
echo-comment
'Echo the comments': a running commentary on all 3 steps:
โฃ
1) Run some Python
๐ Hiss
2) Pause for effect...
3) Complete
Goodbye
comment-echo
'Comment out the echoes': Hiss, no Goodbye:
โฃ
๐ Hiss
Features
- Bidirectional:
echo-comment(comments โ echoes) andcomment-echo(echoes โ comments) - Perfect for Justfiles: Clean recipes that become verbose at runtime
- Preserves formatting: Maintains indentation and structure
- Opt out: Use
##for silent comments that won't be echoed,#\#to echo text starting with# - No dependencies: Ships as a single binary
- Cross-platform: Works on Linux, macOS, and Windows
Installation
Option 1: Install from crates.io
Option 2: Install with cargo-binstall
Option 3: Build from source
Both echo-comment and comment-echo binaries will be installed.
Usage
With Justfiles (Recommended)
Create clean, readable recipes:
# justfile
build-and-publish:
#!/usr/bin/env echo-comment
set -euo pipefail
# ๐งน Cleaning up build artifacts...
find . -name "*.so" -delete || true
# ๐ Running tests...
cargo test
# ๐ Publishing...
cargo publish
When you run just build-and-publish, you'll see:
๐งน Cleaning up build artifacts...
๐ Running tests...
๐ Publishing...
Ship Binary with Your Project
For maximum portability, ship the binary in your repo:
# Build and copy to your project
Then use relative paths in your justfile:
build:
#!/usr/bin/env bin/comment-echo
# Your clean script here...
Standalone Script Usage
# Convert comments to echoes and run
# Convert echoes to comments and run
# Pass arguments to the script
Mode
The tool runs in either mode based on the binary name:
echo-comment: Converts# commentsโecho "comments"comment-echo: Convertsecho "text"โ# text
Examples
Converting Comments to Echoes
Input (script.sh):
#!/usr/bin/env bash
# Starting deployment process
# Waiting for rollout
# Deployment complete!
Running with echo-comment script.sh:
#!/usr/bin/env bash
Converting Echoes to Comments
Input (verbose.sh):
#!/usr/bin/env bash
Running with comment-echo verbose.sh:
#!/usr/bin/env bash
# Backing up database
# Database backed up successfully
Why This Approach?
- Low line noise: Unlike
bash -vorset -x, you just see the comment text - Readability: Foreground your actual logic with syntax highlighting
- Better Diffs: Code changes are separate from message changes
- Maintainability: Makes it trivial to document code
Contributing
Contributions welcome! Please feel free to submit a Pull Request.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.