Skip to content

Instantly share code, notes, and snippets.

@LosAlamosAl
Created January 12, 2022 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LosAlamosAl/aea33f14380ebf604693fe515af6352c to your computer and use it in GitHub Desktop.
Save LosAlamosAl/aea33f14380ebf604693fe515af6352c to your computer and use it in GitHub Desktop.
Persist ZSH history in VSCode

By default, shell hsitory is not persistent across VSCode remote container restarts. To persist, a local (in the container) .zsh_history file must be makked to a file on the host computer. To do this you need to select a unique name to map the local file to. Here is how I do it in my .devcontainer file (only relevant lines shown):

{
    "name": "AWS Development (aws-dev)",
                              ^^^^       this will be the unique name of the history file on the local machine
    "mounts": [
        "source=${env:HOME}${env:USERPROFILE}/.vscode-zsh-hists/aws-dev.zsh_history,target=/home/devboy/.zsh_history,type=bind"
                                                                ^^^^     here's where the mapping occurs
    ]
}

Before building the container for the first time, the local directory and file must exist:

mkdir .vscode-zsh-hists
touch .vscode-zsh-hists/aws-dev.zsh_history
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment