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

npm install @wterm/just-bash just-bash

just-bash 3 is a peer dependency.

Quick Start

import { useCallback, useRef } from "react";
import { Terminal, useTerminal } from "@wterm/react";
import { BashShell } from "@wterm/just-bash";
import "@wterm/react/css";

function App() {
  const { ref, write } = useTerminal();
  const shellRef = useRef<BashShell | null>(null);

  const handleReady = useCallback(() => {
    if (shellRef.current) return;
    const shell = new BashShell({
      files: { "/home/user/hello.txt": "Hello, world!\n" },
      greeting: "Welcome to wterm!",
    });
    shellRef.current = shell;
    shell.attach(write);
  }, [write]);

  const handleData = useCallback((data: string) => {
    shellRef.current?.handleInput(data);
  }, []);

  return (
    <Terminal
      ref={ref}
      onReady={handleReady}
      onData={handleData}
    />
  );
}

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

OptionTypeDefaultDescription
filesRecord<string, string>{}Virtual filesystem (keys are absolute paths, values are file contents)
envRecord<string, string>{ SHELL, TERM }Environment variables
cwdstring"/home/user"Initial working directory
greetingstring | string[]—Lines printed when the shell attaches
prompt(cwd: string) => stringcolored user@wterm:~$Custom prompt function — receives the current working directory
networkNetworkConfig—Network access configuration (see Network Access)

Methods

MethodDescription
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

PropertyTypeDescription
cwdstringCurrent working directory (updates after cd)
bashBash | nullUnderlying 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:

const shell = new BashShell({
  files: {
    "/home/user/README.md": "# My Project\n\nHello, world!\n",
    "/home/user/src/main.zig": 'const std = @import("std");\n',
    "/home/user/data/config.json": '{ "key": "value" }\n',
  },
});

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:

const shell = new BashShell({
  network: {
    dangerouslyAllowFullInternetAccess: true,
  },
});

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.

KeyAction
TabAutocomplete files and commands at the cursor, including when editing earlier words in a command
Up / DownNavigate command history; returning to the newest entry restores your unfinished command and cursor position
Ctrl+RSearch 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 searchFind a newer matching command. Typing continues the search toward newer commands until you press Ctrl+R again.
Left / RightMove cursor within the current line
Backspace / DeleteRemove the character before / at the cursor
Option/Alt+Left / Option/Alt+Right, Ctrl+Left / Ctrl+Right, or Alt+B / Alt+FMove the cursor by word
Option/Alt+Backspace / Ctrl+WRemove the word before the cursor
Home / Ctrl+AJump to start of line
End / Ctrl+EJump to end of line
Ctrl+U / Command+Backspace (macOS)Remove text before the cursor
Ctrl+KRemove text after the cursor
Ctrl+YRestore text removed with Option/Alt+Backspace, Ctrl+W, Ctrl+U, or Ctrl+K; consecutive erasures restore together
Ctrl+CCancel current input or interrupt a running command when it reaches a cancellation point
Ctrl+LClear screen
\ at end of lineLine continuation (multi-line input)