txeh-v1.7.0
This release introduces two major features: inline comment support for organizing and tracking host entries, and MaxHostsPerLine for controlling line length (particularly important for Windows compatibility).
New Features
1. Inline Comment Support
Host entries can now include comments for organization, tracking, and grouping. Comments follow the standard hosts file format: IP HOSTNAME [HOSTNAME...] # comment
How Comments Work
- Grouping by comment: Hosts with the same IP AND same comment are placed on the same line
- Comment isolation: Hosts added without a comment only match lines without a comment
- Comment matching: Hosts added with a comment only match lines with the same comment
- Comment preservation: Comments are never modified on existing lines
- New line creation: If no matching line exists, a new line is created
Library API
// Add hosts with a comment (for grouping/tracking)
hosts.AddHostWithComment("127.0.0.1", "myapp", "local development")
hosts.AddHostsWithComment("127.0.0.1", []string{"svc1", "svc2"}, "my project services")
// Add hosts without a comment (original behavior)
hosts.AddHost("127.0.0.1", "myhost")
hosts.AddHosts("127.0.0.1", []string{"a", "b", "c"})
// List all hosts with a specific comment
devHosts := hosts.ListHostsByComment("local development")
// Remove all entries with specific comments
hosts.RemoveByComment("old environment")
hosts.RemoveByComments([]string{"deprecated", "temp"})CLI Usage
# Add host with a comment
sudo txeh add 127.0.0.1 myapp --comment "local development"
# Result: 127.0.0.1 myapp # local development
# Add another host with the same comment (groups together)
sudo txeh add 127.0.0.1 myapp2 --comment "local development"
# Result: 127.0.0.1 myapp myapp2 # local development
# Add host with a different comment (new line)
sudo txeh add 127.0.0.1 api --comment "staging environment"
# Result: 127.0.0.1 api # staging environment
# List all hosts with a specific comment
sudo txeh list bycomment "local development"
# Remove all entries with a specific comment
sudo txeh remove bycomment "local development"2. MaxHostsPerLine Configuration
Control the maximum number of hostnames per line. This is particularly important for Windows, which only reads the first 9 hostnames per line (additional hostnames are silently ignored).
Note: The Windows 9-host limit is empirically observed behavior, not officially documented by Microsoft. See: kubefwd#258, ddev#948, crc#2710
Configuration Values
| Value | Behavior |
|---|---|
0 (default) |
Auto mode: 9 hosts per line on Windows, unlimited elsewhere |
-1 |
Force unlimited (no wrapping) |
>0 |
Explicit limit (e.g., 5 means max 5 hosts per line) |
Library API
hosts, err := txeh.NewHosts(&txeh.HostsConfig{
MaxHostsPerLine: 9, // Explicit limit
})
// Or use auto mode (default)
hosts, err := txeh.NewHostsDefault() // Uses 9 on Windows, unlimited elsewhereCLI Usage
# Set explicit limit
sudo txeh add 127.0.0.1 host1 host2 host3 --max-hosts-per-line 2
# Use auto mode (default, 9 on Windows)
sudo txeh add 127.0.0.1 host1 host2 host3
# Force unlimited
sudo txeh add 127.0.0.1 host1 host2 host3 --max-hosts-per-line -1CLI Changes
New Flags
| Flag | Short | Description |
|---|---|---|
--comment |
-c |
Add comment to host entry (for add command) |
--max-hosts-per-line |
-m |
Max hostnames per line (0=auto, -1=unlimited, >0=explicit) |
New Subcommands
| Command | Description |
|---|---|
txeh list bycomment "COMMENT" |
List all hosts with a specific comment |
txeh remove bycomment "COMMENT" |
Remove all entries with a specific comment |
API Additions
New Methods
| Method | Description |
|---|---|
AddHostWithComment(address, hostname, comment string) |
Add a host with an inline comment |
AddHostsWithComment(address string, hostnames []string, comment string) |
Add multiple hosts with an inline comment |
ListHostsByComment(comment string) []string |
Get all hostnames with a specific comment |
RemoveByComment(comment string) |
Remove all entries with a specific comment |
RemoveByComments(comments []string) |
Remove all entries with any of the specified comments |
New HostsConfig Field
| Field | Type | Description |
|---|---|---|
MaxHostsPerLine |
int |
Maximum hostnames per line (0=auto, -1=unlimited, >0=explicit) |
Use Cases
Tracking Tool-Managed Entries
# Docker adding entries
sudo txeh add 127.0.0.1 app.local --comment "docker"
# Kubernetes port-forward (kubefwd)
sudo txeh add 127.0.0.1 myservice.mynamespace --comment "kubefwd"
# Clean up all entries from a specific tool
sudo txeh remove bycomment "docker"Development Environment Organization
# Add dev services
sudo txeh add 127.0.0.1 api.local web.local --comment "dev services"
sudo txeh add 127.0.0.1 db.local cache.local --comment "dev services"
# Add staging services (separate line)
sudo txeh add 192.168.1.100 api.staging --comment "staging"
# List dev services
sudo txeh list bycomment "dev services"Modifying Comments
Comments are never modified on existing lines. To change a comment, remove and re-add:
# Remove all entries with the old comment
sudo txeh remove bycomment "old comment"
# Re-add with the new comment
sudo txeh add 127.0.0.1 app1 app2 --comment "new comment"Full Changelog
Features
- Add inline comment support for host entries
- Add
AddHostWithComment()andAddHostsWithComment()methods - Add
ListHostsByComment()method - Add
RemoveByComment()andRemoveByComments()methods - Add
--comment/-cflag to CLIaddcommand - Add
list bycommentCLI subcommand - Add
remove bycommentCLI subcommand - Add
MaxHostsPerLineconfiguration option - Add
--max-hosts-per-line/-mCLI flag - Auto-detect Windows and apply 9-host limit by default
Testing
- Add comprehensive tests for comment functionality
- Add tests for MaxHostsPerLine and Windows 9-host limit
- Add whitespace handling tests for comments
Documentation
- Add comprehensive "Comments" section to README
- Document comment matching behavior
- Add CLI and library usage examples
- Update CLI help output with new flags
Installation
CLI
# Using Go install (requires Go 1.24+)
go install github.com/txn2/txeh/txeh@v1.7.0
# Using Homebrew
brew install txn2/tap/txehLibrary
go get github.com/txn2/txeh@v1.7.0Checksums
See the assets below for SHA256 checksums of all release binaries.