devcontainers / devcontainers/features

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

Open
#1,451 1 comment 3 reactions 1 assignee Claimed by @v-Mathiyarasy View on GitHub
Dominant language
Shell
Stars
1.5k
Forks
621
Avg merge
2d 11h
Merged PRs (30d)
4

Description

## 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:
```json
"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
```json
{
"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:
```json
"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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.