Skip to content
bun-shell-commands logo

Bun Shell Commands

bun-shell-commands

Writing shell commands for OpenCode custom commands using Bun Shell

SKILL.md

Full skill instructions

Bun Shell Commands

This skill covers how to write effective shell commands in OpenCode custom commands using Bun Shell (Bun's bash-like shell implementation).

Context

OpenCode uses Bun Shell for executing shell commands in custom commands via the !command syntax. Bun Shell is a bash-like shell written in Zig that provides cross-platform shell scripting, but it has some differences from traditional bash.

Supported Features

✅ Arguments

Positional arguments work correctly:

!`echo "Arg1: $1" && echo "Arg2: $2" && echo "Arg3: $3"`

Usage: /​mycommand 5 "hello world" "a,b,c"

✅ Command Substitution

Use $(command) for command substitution:

!`echo "Sum: $(seq $1 | awk '{s+=$1} END {print s}')"`

✅ Pipes

Pipe commands using |:

!`echo "$2" | tr '[:lower:]' '[:upper:]' | rev`

✅ Environment Variables

Set environment variables and use them:

!`TEST_VAR="$1" && echo "TEST_VAR=$TEST_VAR"`

Store command substitution results in variables:

!`REV=$(echo "$2" | rev) && echo "Reversed: $REV"`

✅ Command Chaining

Use && to chain commands (instead of newlines or ;):

!`echo "First" && echo "Second" && echo "Third"`

✅ Available Commands

Bun Shell includes these built-in commands:

  • cd, ls, rm, echo, pwd, cat, touch, mkdir, which, mv
  • seq, dirname, basename, true, false, yes

Common external commands also work:

  • awk, sed, tr, wc, grep, head, tail
  • find, xargs, sort, uniq

Unsupported Features

❌ Shell Control Structures

Do NOT use for, while, do, done:

# ❌ DOESN'T WORK
!`for i in $(seq 1 $1); do echo $i; done`

❌ Arithmetic Expansion

Do NOT use $(( )) directly in the template:

# ❌ DOESN'T WORK
!`echo "Squared: $(($1 * $1))"`

Use $(awk '{...}') instead:

# ✅ WORKS
!`echo "$1" | awk '{print $1 * $1}'`

❌ Native Brace Expansion

Native brace expansion is not supported:

# ❌ DOESN'T WORK
!`echo {1,2,3}`

Use pipes to simulate expansion:

# ✅ WORKS
!`echo "$3" | tr ',' '\n' | awk '{print "Expanded:", $1}'`

Patterns and Best Practices

Loops via Pipes

Instead of for loops, use seq with awk:

# Generate numbers 1 to N with squares
!`seq $1 | awk '{print $1, "-> squared:", $1*$1}'`

Multi-step Operations

Use environment variables to store intermediate results:

# Reverse text, count chars, and show both
!`REV=$(echo "$2" | rev) && COUNT=$(echo "$2" | wc -c) && echo "Reversed: $REV (${COUNT} chars)"`

Conditional Logic

Use awk for conditionals:

# Classify numbers as even/​odd
!`seq $1 | awk '{if ($1 % 2 == 0) print $1 ": even"; else print $1 ": odd"}'`

Text Processing

Combine tr, sed, awk for text manipulation:

# Uppercase, reverse, and format
!`echo "$2" | tr '[:lower:]' '[:upper:]' | rev | sed 's/^/> /'`

Working with Multiple Arguments

Use separate shell blocks for independent tests:

## Test 1: Arithmetic with $1
!`seq $1 | awk '{s+=$1} END {print "Sum:", s}'`

## Test 2: Text processing with $2
!`echo "$2" | tr '[:lower:]' '[:upper:]' | rev`

## Test 3: Pattern with $3
!`echo "$3" | tr ',' '\n' | wc -l`

Example: Complete Command

---
description: Test Bun Shell capabilities
---

Test Bun Shell with multiple features:

## Argument passing
!`echo "Arg1: [$1]" && echo "Arg2: [$2]" && echo "Arg3: [$3]"`

## Command substitution
!`echo "Sum of 1 to $1: $(seq $1 | awk '{s+=$1} END {print s}')"`

## Text processing
!`echo "$2" | tr '[:lower:]' '[:upper:]' | rev | wc -c`

## Environment variables
!`REV=$(echo "$2" | rev) && echo "Reversed via var: $REV"`

Usage: /​mycommand 5 "hello world" "a,b,c"

Debugging

If a shell command fails silently:

  1. Simplify to just echo "$1" to verify argument passing
  2. Test each pipe segment separately
  3. Replace complex awk with simpler tr or sed
  4. Use echo at each step to verify intermediate values

References

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View