gbash

Contrib Commands

Contrib commands are optional, community-backed implementations shipped as separate Go modules under github.com/ewhauser/gbash/contrib/. They are not included in the default registry.

Available Commands

awk

Pattern scanning and text processing language, backed by benhoyt/goawk.

import contribawk "github.com/ewhauser/gbash/contrib/awk"
echo "alice 30\nbob 25" | awk '{print $1}'
awk -F',' '{sum += $2} END {print sum}' data.csv

html-to-markdown

HTML to Markdown converter, backed by JohannesKaufmann/html-to-markdown.

import contribhtmltomarkdown "github.com/ewhauser/gbash/contrib/htmltomarkdown"
echo '<h1>Hello</h1><p>World</p>' | html-to-markdown
html-to-markdown page.html

jq

Lightweight JSON processor, backed by itchyny/gojq.

import contribjq "github.com/ewhauser/gbash/contrib/jq"
echo '{"name":"alice","age":30}' | jq '.name'
cat data.json | jq '.items[] | select(.active == true)'

sqlite3

SQLite database shell, backed by ncruces/go-sqlite3.

import contribsqlite3 "github.com/ewhauser/gbash/contrib/sqlite3"
sqlite3 :memory: "CREATE TABLE t(x); INSERT INTO t VALUES(1),(2),(3); SELECT sum(x) FROM t;"

yq

YAML, JSON, and XML processor, backed by mikefarah/yq.

import contribyq "github.com/ewhauser/gbash/contrib/yq"
echo "name: alice" | yq '.name'
yq -i '.version = "2.0"' config.yaml

Registering Contrib Commands

Register All at Once

Use extras.FullRegistry() to get the default registry plus the stable contrib commands in a single call:

import "github.com/ewhauser/gbash/contrib/extras"
 
registry := extras.FullRegistry()
gb, err := gbash.New(gbash.WithRegistry(registry))

Register Individually

Add specific contrib modules to an existing registry:

import (
    "github.com/ewhauser/gbash"
    contribjq "github.com/ewhauser/gbash/contrib/jq"
)
 
registry := gbash.DefaultRegistry()
if err := contribjq.Register(registry); err != nil {
    log.Fatal(err)
}
gb, err := gbash.New(gbash.WithRegistry(registry))

gbash-extras CLI

The gbash-extras CLI is a drop-in replacement for the gbash CLI with the stable contrib commands pre-registered:

go install github.com/ewhauser/gbash/contrib/extras/cmd/gbash-extras@latest
echo '{"a":1}' | gbash-extras -c 'jq .a'

Custom Command Registration

You can register your own commands using the same mechanism the contrib modules use. See the custom-zstd example for a complete walkthrough that implements a zstd compression command using commands.DefineCommand and registry.Register.