Skip to content

[Feature] Add shell history persistence option to common-utils #1451

@baxyz

Description

@baxyz

Summary

Add a new option to the common-utils feature to automatically persist shell history (bash/zsh) across container rebuilds, eliminating the need for manual mounts in devcontainer.json.

Problem Statement

Currently, shell command history is lost when dev containers are rebuilt. Users must manually configure mounts in their devcontainer.json to persist history, which requires:

  1. Creating a local directory structure (e.g., .devcontainer/data/)
  2. Adding manual mounts like:
"mounts": [
    "source=${localWorkspaceFolder}/.devcontainer/data/zsh_history,target=/home/vscode/.zsh_history,type=bind,consistency=cached"
]

This is a common need but requires manual setup that could be automated.

Proposed Solution

Add a new boolean option persistHistory (or similar) to the common-utils feature that would:

  1. When enabled: Automatically configure the container to persist shell history files
  2. Implementation approach:
    • Create a standard directory structure for history persistence
    • Configure appropriate symbolic links or mount points
    • Handle both bash (.bash_history) and zsh (.zsh_history) histories
    • Work with different user configurations (vscode, root, custom users)

Example Usage

{
  "features": {
    "ghcr.io/devcontainers/features/common-utils:2": {
      "installZsh": true,
      "installOhMyZsh": true,
      "persistHistory": true
    }
  }
}

Benefits

  • Improved Developer Experience: History persistence works out-of-the-box
  • Consistency: Standardized approach across different dev containers
  • Reduced Configuration: No need for manual mounts configuration
  • Best Practices: Automated implementation of a common pattern

Current Workaround

Users currently need to manually add mounts like:

"mounts": [
    "source=${localWorkspaceFolder}/.devcontainer/data/zsh_history,target=/home/vscode/.zsh_history,type=bind,consistency=cached"
]

Additional Context

This feature would complement the existing shell-related options (installZsh, installOhMyZsh, etc.) by completing the shell experience with history persistence.

The feature should be:

  • Optional: Disabled by default to maintain backward compatibility
  • Cross-platform: Work with different base images and distributions
  • Multi-user: Support different username configurations
  • Shell-agnostic: Work with both bash and zsh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions