Just Bash
Shell adapter for wterm, powered by just-bash. Provides line editing, tab completion, command history, and a colored prompt — all running in the browser with no backend.
Install
just-bash 3 is a peer dependency.
Quick Start
Use a ref to hold the BashShell instance so it's accessible from both the onReady and onData callbacks.
Each submitted command runs once. After it completes, the shell automatically updates its working directory and prompt from the command's final directory, including when a command exits with a nonzero status.
Options
| Option | Type | Default | Description |
|---|---|---|---|
files | Record<string, string> | {} | Virtual filesystem (keys are absolute paths, values are file contents) |
env | Record<string, string> | { SHELL, TERM } | Environment variables |
cwd | string | "/home/user" | Initial working directory |
greeting | string | string[] | — | Lines printed when the shell attaches |
prompt | (cwd: string) => string | colored user@wterm:~$ | Custom prompt function — receives the current working directory |
network | NetworkConfig | — | Network access configuration (see Network Access) |
Methods
| Method | Description |
|---|---|
attach(write): Promise<void> | Connect to a terminal write function. Loads just-bash, prints the greeting, and displays the initial prompt. |
handleInput(data): Promise<void> | Process terminal input (keystrokes, paste). Call this from the terminal's onData callback. |
Properties
| Property | Type | Description |
|---|---|---|
cwd | string | Current working directory (updates after cd) |
bash | Bash | null | Underlying just-bash instance (null until attach completes) |
Virtual Filesystem
The files option populates an in-memory filesystem. Keys are absolute paths, values are file contents:
Directories are created implicitly from file paths. Commands like ls, cat, cd, and pwd work against this virtual filesystem.
Network Access
By default, the shell runs fully offline. To enable network access (for commands like curl or fetch), pass the network option from just-bash:
The NetworkConfig type is re-exported from just-bash. See the just-bash documentation for all available network options.
Keyboard Shortcuts
The command line accepts pasted Unicode text and treats emoji and combining sequences as whole characters when moving or deleting. Cursor movement uses terminal columns, keeping wide characters aligned.
| Key | Action |
|---|---|
Tab | Autocomplete files and commands at the cursor, including when editing earlier words in a command |
Up / Down | Navigate command history; returning to the newest entry restores your unfinished command and cursor position |
Ctrl+R | Search command history from newest to oldest as you type; press again to find an older match. Enter runs the match, Escape accepts it for editing, and Ctrl+G restores your unfinished command. |
Ctrl+S during history search | Find a newer matching command. Typing continues the search toward newer commands until you press Ctrl+R again. |
Left / Right | Move cursor within the current line |
Backspace / Delete | Remove the character before / at the cursor |
Option/Alt+Left / Option/Alt+Right, Ctrl+Left / Ctrl+Right, or Alt+B / Alt+F | Move the cursor by word |
Option/Alt+Backspace / Ctrl+W | Remove the word before the cursor |
Home / Ctrl+A | Jump to start of line |
End / Ctrl+E | Jump to end of line |
Ctrl+U / Command+Backspace (macOS) | Remove text before the cursor |
Ctrl+K | Remove text after the cursor |
Ctrl+Y | Restore text removed with Option/Alt+Backspace, Ctrl+W, Ctrl+U, or Ctrl+K; consecutive erasures restore together |
Ctrl+C | Cancel current input or interrupt a running command when it reaches a cancellation point |
Ctrl+L | Clear screen |
\ at end of line | Line continuation (multi-line input) |