Simple, cross-platform, and fast command aliases with superpowers.
A fork of Bonnie with a shorter, snappier command name.
Releases | Bonnie Documentation
- Short - Only 2 characters to type (vs 6 for "bonnie")
- Unique - Fairly unused command name in the Linux/macOS world
- Meaningful - Can stand for "bonnie execute" or "Benny execute"
bx is a command aliasing tool that lets you define short aliases for long commands you run repeatedly. Here's what it supports:
- Simple key-value aliasing
- Inserting custom arguments into commands
- Interpolating environment variables
- Adding all arguments in a single place
- Using different commands on different operating systems
- Specifying custom shells for individual commands
- Specifying default shells for different OSes on a per-file basis
- Infinitely nestable subcommands
- Subcommands executed in a certain order based on exit codes
- Caching large config files after parsing for performance
- Initializing new config files from templates
- Global templates in
~/.bx/template.toml - Debug mode
If you have commands you routinely run in a project, bx is for you.
Create bx.toml (or bonnie.toml) in your project root:
version = "0.3.2"
[scripts]
build = "cargo build"
test = "cargo test"
dev = "cargo run -- %%"
greet = "echo 'Hello, %name!'"bx build # Runs: cargo build
bx test # Runs: cargo test
bx dev --release # Runs: cargo run -- --release
bx greet Perseus # Runs: echo 'Hello, Perseus!'cargo install bx-cliDownload pre-built binaries from the releases page for:
- Linux (amd64)
- macOS (amd64, arm64)
- Windows (amd64)
- musl (Alpine Linux)
After downloading:
chmod +x bx
sudo mv bx /usr/local/bin/RUN curl -L https://github.com/codemonument/bx/releases/download/v0.4.0/bx-linux-amd64 \
-o /usr/local/bin/bx && chmod +x /usr/local/bin/bxFor Alpine Linux, use bx-musl-amd64 instead.
bx looks for configuration files in this order:
BX_CONFenvironment variablebx.tomlin current directoryBONNIE_CONFenvironment variablebonnie.tomlin current directory
version = "0.3.2"
[scripts]
build = "cargo build"
test = "cargo test"
clean = "cargo clean"Use %% to pass all remaining arguments, or %name for named arguments:
[scripts]
# Pass all arguments
run = "cargo run -- %%"
# Named argument (required)
greet = "echo 'Hello, %name!'"
# Named argument with default
greet.cmd = "echo 'Hello, %name!'"
greet.args = ["name=World"]bx run --release # cargo run -- --release
bx greet Alice # echo 'Hello, Alice!'
bx greet # echo 'Hello, World!' (uses default)Interpolate environment variables with %varname:
[scripts]
deploy = "rsync -avz ./dist/ %USER@%HOST:/var/www/"
[scripts.deploy.env]
HOST = "example.com"You can also load from .env files:
[env]
files = [".env", ".env.local"]Run multiple commands in sequence:
[scripts]
ci = [
"cargo fmt -- --check",
"cargo clippy",
"cargo test"
]Nest commands for better organization:
[scripts.db]
db.subcommands.migrate = "diesel migration run"
db.subcommands.reset = "diesel database reset"
db.subcommands.seed = "cargo run --bin seed"bx db migrate
bx db reset
bx db seedRun different commands on different operating systems:
[scripts.open]
cmd.generic = "xdg-open %%"
cmd.targets.windows = "start %%"
cmd.targets.macos = "open %%"Override the default shell for specific commands:
[scripts]
# Use PowerShell on Windows
build.cmd = "Write-Host 'Building...'; cargo build"
build.shell = ["powershell", "-Command", "{}"]
# Use Node.js
calc.cmd = "console.log(2 + 2)"
calc.shell = ["node", "-e", "{}"]Set default shells globally or per-OS:
# Global default
default_shell = ["bash", "-c", "{}"]
# Per-OS defaults
[default_shell.targets]
windows = ["powershell", "-Command", "{}"]
macos = ["zsh", "-c", "{}"]
linux = ["bash", "-c", "{}"]Bones is a mini-language for defining subcommands that execute based on exit codes:
[scripts]
test.cmd.generic = """
start {
unit => cargo test --lib {
pass => integration => cargo test --test '*'
}
}
"""This runs unit tests first, and only runs integration tests if unit tests pass.
See the Bonnie documentation on Bones for full syntax.
For large config files, enable caching for faster startup:
bx -c # Cache the current config
bx build # Subsequent runs use the cacheThe cache is stored at .bx.cache.json (or .bonnie.cache.json).
Initialize new projects from templates:
bx -t # Initialize from default templateTemplates are stored in ~/.bx/template.toml (or ~/.bonnie/template.toml).
See exactly what commands bx will execute:
bx -d build # Shows the command without running itBash aliases can't be customized per-folder. If you want to interpolate arguments or environment variables, you need scripts. bx solves this with simple, intuitive syntax that just works, and it's cross-platform.
GNU Make was designed to recompile files when dependencies change. Its syntax is clunky for simple command aliasing. bx uses TOML, which is human-readable and only requires configuration for features you actually use.
npm scripts don't support comments, have poor environment variable handling, and require Node.js. bx is a single binary with no runtime dependencies.
bx is a drop-in replacement for Bonnie:
- Install bx:
cargo install bx-cli - Your existing
bonnie.tomlfiles work as-is - Optionally rename to
bx.toml - Replace
bonniewithbxin your commands
MIT - See LICENSE
Based on Bonnie by arctic_hen7.