diff --git a/DOCKER_HUB.md b/DOCKER_HUB.md index f8ea063..3c35cca 100644 --- a/DOCKER_HUB.md +++ b/DOCKER_HUB.md @@ -227,6 +227,7 @@ Understanding what survives container restarts and what doesn't: | `/home/developer/.aws` | Host bind mount | ✅ Yes — lives on host | AWS credentials/SSO cache | | `/home/developer/.local/share/opencode` | Named volume (if configured) | ✅ Yes — Docker volume | Session history, memory, auth tokens | | `/home/developer/.local/state/opencode` | Named volume (if configured) | ✅ Yes — Docker volume | TUI settings (theme, toggles) | +| `/home/developer/.cache/bash` | Named volume `devbox-shell-history` | ✅ Yes — Docker volume | Bash history (`$HISTFILE`) — survives container recreate | | `/home/developer/.local/share/uv` | Named volume (if configured) | ✅ Yes — Docker volume | Python installs, uv tool installs | | `/home/developer/.rustup` | Named volume (if configured) | ✅ Yes — Docker volume | Rust toolchains | | `/home/developer/.cargo` | Named volume (if configured) | ✅ Yes — Docker volume | Cargo binaries, registry cache | @@ -239,6 +240,7 @@ Understanding what survives container restarts and what doesn't: - **opencode config** is auto-generated from `OPENCODE_PROVIDER` env var on each start if no existing config is found. To persist config changes, mount the config directory from the host (see Custom opencode Config below). - **opencode data** (session history, memory) is lost on container recreation unless you add a named volume. - **TUI settings** (theme, toggles) are lost on container recreation unless you add the `devbox-state` named volume. +- **Bash history** persists via the `devbox-shell-history` volume mounted at `~/.cache/bash`. `HISTFILE` is pre-configured; no setup required. - **Python installs** via `uv python install` are lost on container recreation unless you add the `devbox-uv` named volume. - **Rust toolchains** via `rustup-init` are lost on container recreation unless you add the `devbox-rustup` and `devbox-cargo` named volumes. - **AWS SSO tokens** persist across restarts when `~/.aws` is mounted (recommended for Bedrock users). @@ -463,6 +465,19 @@ docker compose run --rm devbox # direct to opencode docker compose run --rm devbox bash # interactive shell ``` +## Shell defaults + +The image ships baked shell defaults in `~/.bash_aliases` and `~/.inputrc`: + +- **Prefix history search** on Up/Down arrows (type `git `, press Up, walk back through prior `git ...` commands only). Ctrl-Up / Ctrl-Down still step through full history. +- **Persistent history** via `$HISTFILE=~/.cache/bash/history`, backed by the `devbox-shell-history` named volume. Survives container recreate. 100 000 entries, time-stamped, dedup. +- **Case-insensitive tab completion** and coloured completion lists. +- **Aliases** — `ls`/`ll`/`la` → `eza`, `cat` → `bat`, `gs`/`gd`/`gl` for git, interactive `rm`/`mv`/`cp`. +- **Integrations** — `zoxide` (`z `), `fzf` key bindings (`Ctrl-R`, `Ctrl-T`). +- **`[devbox]` prompt prefix** so you always know you're in the container. + +To override with your host's own `~/.bash_aliases` / `~/.inputrc`, uncomment the matching bind-mount lines in `docker-compose.yml`. + ## What's Included ### Base image (`latest`) diff --git a/Dockerfile b/Dockerfile index 47669e5..7a761fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -200,9 +200,19 @@ RUN mkdir -p /workspace \ /home/${USER_NAME}/.config/opencode/skills \ /home/${USER_NAME}/.agents/skills \ /home/${USER_NAME}/.local/share/opencode \ + /home/${USER_NAME}/.cache/bash \ /home/${USER_NAME}/.ssh && \ chown -R ${USER_NAME}:${USER_NAME} /workspace /home/${USER_NAME} +# ── Shell defaults (bash history, aliases, readline) ───────────────── +# Baked into the image so a fresh container has sensible history and +# readline behaviour out of the box. Users can override by bind-mounting +# their host ~/.inputrc or ~/.bash_aliases via docker-compose.yml. +# History itself persists via the devbox-shell-history named volume +# mounted at ~/.cache/bash (HISTFILE points there). +COPY --chown=${USER_UID}:${USER_GID} rootfs/home/developer/.bash_aliases /home/${USER_NAME}/.bash_aliases +COPY --chown=${USER_UID}:${USER_GID} rootfs/home/developer/.inputrc /home/${USER_NAME}/.inputrc + # ── Entrypoint ──────────────────────────────────────────────────────── COPY entrypoint.sh /usr/local/bin/entrypoint.sh COPY entrypoint-user.sh /usr/local/bin/entrypoint-user.sh diff --git a/README.md b/README.md index 7f0fca8..95554fb 100644 --- a/README.md +++ b/README.md @@ -438,6 +438,24 @@ The `--use-device-code` flag outputs a URL and short code instead of trying to o SSO sessions typically last 8–12 hours before requiring re-authentication. Since `~/.aws` is mounted from the host, tokens persist across container restarts. +## Shell defaults + +The image ships a baked `~/.bash_aliases` and `~/.inputrc` with quality-of-life defaults: + +- **Prefix history search** on Up/Down arrows (type `git `, press Up, walk back through prior `git ...` commands only). Ctrl-Up / Ctrl-Down still step through full history. +- **Persistent history** — `$HISTFILE` points at `~/.cache/bash/history`, backed by the `devbox-shell-history` named volume so history survives container recreation. Timestamps, 100 000 entries, dedup. +- **Case-insensitive tab completion**, coloured completion lists, `show-all-if-ambiguous`. +- **Aliases** — `ls`/`ll`/`la` use `eza`, `cat` uses `bat`, `gs`/`gd`/`gl` for git, safe `rm`/`mv`/`cp`. +- **Integrations** — `zoxide` (`z ` to jump), `fzf` Ctrl-R / Ctrl-T key bindings. +- **Prompt marker** — `[devbox]` prefix so it's always obvious you're inside the container. + +To override with your own host config, uncomment the bind-mount lines in `docker-compose.yml`: + +```yaml +- ~/.bash_aliases:/home/developer/.bash_aliases:ro +- ~/.inputrc:/home/developer/.inputrc:ro +``` + ## Secret Scanning A [gitleaks](https://github.com/gitleaks/gitleaks) pre-commit hook prevents accidentally committing API keys, passwords, or other secrets. @@ -496,6 +514,7 @@ Container (Debian trixie) | `/home/developer/.aws` | Host bind mount (if configured) | ✅ Yes | AWS credentials/SSO cache | | `/home/developer/.local/share/opencode` | Named volume `devbox-data` | ✅ Yes | Session history, memory | | `/home/developer/.local/state/opencode` | Named volume `devbox-state` | ✅ Yes | TUI settings (theme, toggles) | +| `/home/developer/.cache/bash` | Named volume `devbox-shell-history` | ✅ Yes | Bash history (`$HISTFILE`), survives container recreate | | `/home/developer/.local/share/uv` | Named volume `devbox-uv` (if configured) | ✅ Yes | Python installs, uv tool installs | | `/home/developer/.rustup` | Named volume `devbox-rustup` (if configured) | ✅ Yes | Rust toolchains | | `/home/developer/.cargo` | Named volume `devbox-cargo` (if configured) | ✅ Yes | Cargo binaries, registry cache | diff --git a/docker-compose.shared.yml b/docker-compose.shared.yml index 28d81d5..53675ba 100644 --- a/docker-compose.shared.yml +++ b/docker-compose.shared.yml @@ -39,6 +39,9 @@ services: # Persist opencode data (auth, memory, session history) - devbox-data:/home/developer/.local/share/opencode + # Persist bash history across container recreations + - devbox-shell-history:/home/developer/.cache/bash + # Persist uv data (Python installs) - devbox-uv:/home/developer/.local/share/uv @@ -47,4 +50,5 @@ services: volumes: devbox-data: + devbox-shell-history: devbox-uv: diff --git a/docker-compose.yml b/docker-compose.yml index f39a917..8fbbcec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -52,6 +52,16 @@ services: # Optional: persist opencode TUI settings (theme, toggles, etc.) - devbox-state:/home/developer/.local/state/opencode + # Persist bash history across container recreations. + # Without this, ~/.bash_history is lost on 'docker compose up --force-recreate'. + - devbox-shell-history:/home/developer/.cache/bash + + # Optional: override baked shell defaults with your host's rc files. + # The image ships sensible defaults (history tuning, prefix-search on + # Up/Down arrows, fzf/zoxide integration). Uncomment to use your own: + # - ~/.bash_aliases:/home/developer/.bash_aliases:ro + # - ~/.inputrc:/home/developer/.inputrc:ro + # Optional: persist uv data (Python installs, tool installs) # Without this, 'uv python install' must be re-run after container removal. - devbox-uv:/home/developer/.local/share/uv @@ -70,6 +80,7 @@ services: volumes: devbox-data: devbox-state: + devbox-shell-history: devbox-uv: # devbox-rustup: # devbox-cargo: diff --git a/entrypoint.sh b/entrypoint.sh index b00dbaf..dc85123 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -66,6 +66,7 @@ for parent in \ /home/"$USER_NAME"/.local \ /home/"$USER_NAME"/.local/share \ /home/"$USER_NAME"/.local/state \ + /home/"$USER_NAME"/.cache \ /home/"$USER_NAME"/.config; do if [ -d "$parent" ] && [ "$(stat -c '%u' "$parent" 2>/dev/null)" != "$FINAL_UID" ]; then chown "$FINAL_UID":"$FINAL_GID" "$parent" 2>/dev/null || true @@ -76,6 +77,7 @@ for dir in \ /home/"$USER_NAME"/.local/share/opencode \ /home/"$USER_NAME"/.local/state/opencode \ /home/"$USER_NAME"/.local/share/uv \ + /home/"$USER_NAME"/.cache/bash \ /home/"$USER_NAME"/.rustup \ /home/"$USER_NAME"/.cargo \ /home/"$USER_NAME"/.vscode-server \ diff --git a/rootfs/home/developer/.bash_aliases b/rootfs/home/developer/.bash_aliases new file mode 100644 index 0000000..7932036 --- /dev/null +++ b/rootfs/home/developer/.bash_aliases @@ -0,0 +1,73 @@ +# opencode-devbox bash aliases and customizations +# Sourced by the Debian-default ~/.bashrc on shell startup. +# To override, bind-mount your host's ~/.bash_aliases over this file +# via docker-compose.yml. + +# ── History persistence and quality ────────────────────────────────── +# The named volume devbox-shell-history is mounted at ~/.cache/bash +# so history survives container recreation. +export HISTFILE="${HOME}/.cache/bash/history" +mkdir -p "$(dirname "$HISTFILE")" 2>/dev/null || true + +# Large, time-stamped, deduplicated history. Append rather than overwrite. +export HISTSIZE=100000 +export HISTFILESIZE=200000 +export HISTCONTROL=ignoreboth:erasedups +export HISTTIMEFORMAT='%F %T ' +shopt -s histappend 2>/dev/null +shopt -s cmdhist 2>/dev/null +# Flush every command to disk immediately so reboots don't lose recent work. +# Guarded so repeated sourcing (e.g. `exec bash`) doesn't stack duplicates. +if [ -z "${DEVBOX_HIST_SET:-}" ]; then + PROMPT_COMMAND="history -a; ${PROMPT_COMMAND:-}" + export DEVBOX_HIST_SET=1 +fi + +# ── Common aliases ─────────────────────────────────────────────────── +# Prefer eza (modern ls) when available +if command -v eza >/dev/null 2>&1; then + alias ls='eza --group-directories-first' + alias ll='eza -lh --group-directories-first --git' + alias la='eza -lha --group-directories-first --git' + alias tree='eza --tree' +else + alias ll='ls -lh' + alias la='ls -lha' +fi + +# Prefer bat (syntax-highlighted cat) when available +if command -v bat >/dev/null 2>&1; then + alias cat='bat --style=plain --paging=never' + alias less='bat --paging=always' +fi + +# Git shortcuts +alias gs='git status' +alias gd='git diff' +alias gl='git log --oneline --graph --decorate -20' + +# Safety: confirm before destructive ops +alias rm='rm -i' +alias mv='mv -i' +alias cp='cp -i' + +# ── Shell integrations ─────────────────────────────────────────────── +# zoxide — smarter cd. Use 'z ' to jump to previously-visited dirs. +if command -v zoxide >/dev/null 2>&1; then + eval "$(zoxide init bash)" +fi + +# fzf — fuzzy finder key bindings (Ctrl-R for history, Ctrl-T for files). +# We install fzf from GitHub releases (not apt), so sourcing from the +# apt-path /usr/share/doc/fzf/examples/* would find nothing. Use the +# binary's own --bash flag (available since fzf 0.48) for setup. +if command -v fzf >/dev/null 2>&1; then + eval "$(fzf --bash)" 2>/dev/null || true +fi + +# ── Prompt: show [opencode-devbox] tag so it's obvious you're in the container +# Preserves the default Debian PS1 logic but prefixes with a container marker. +if [ -n "${PS1:-}" ] && [ -z "${DEVBOX_PS1_SET:-}" ]; then + PS1='\[\e[38;5;39m\][devbox]\[\e[0m\] '"${PS1}" + export DEVBOX_PS1_SET=1 +fi diff --git a/rootfs/home/developer/.inputrc b/rootfs/home/developer/.inputrc new file mode 100644 index 0000000..f7a2406 --- /dev/null +++ b/rootfs/home/developer/.inputrc @@ -0,0 +1,27 @@ +# opencode-devbox readline defaults +# To override, bind-mount your host's ~/.inputrc over this file +# via docker-compose.yml. + +# Inherit system-wide defaults (colour, 8-bit input, …) if present +$include /etc/inputrc + +# ── History search on Up/Down ──────────────────────────────────────── +# Type a prefix, press Up, and walk through previous commands starting +# with that prefix. Ctrl-Up / Ctrl-Down keep the unconditional stepper. +"\e[A": history-search-backward +"\e[B": history-search-forward +"\e[1;5A": previous-history +"\e[1;5B": next-history + +# ── Completion quality ─────────────────────────────────────────────── +set show-all-if-ambiguous on # single Tab shows matches on ambiguity +set completion-ignore-case on # case-insensitive file/dir completion +set colored-stats on # colour ls-style completion list entries +set colored-completion-prefix on # highlight the matched prefix +set visible-stats on # append /*@ type indicators in completion +set mark-symlinked-directories on # add trailing / to symlinks to dirs +set skip-completed-text on # don't re-insert already-typed text + +# Treat hyphens and underscores as equivalent when completing (e.g. +# typing `foo-` matches both `foo-bar` and `foo_bar`). +set completion-map-case on