Skip to content

Save shell history before WSL termination on restart#469

Open
Copilot wants to merge 3 commits intodevelopmentfrom
copilot/save-shell-history-on-termination
Open

Save shell history before WSL termination on restart#469
Copilot wants to merge 3 commits intodevelopmentfrom
copilot/save-shell-history-on-termination

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

  • Add history -a before wsl.exe --terminate to flush history to disk
  • Add error suppression (2>/dev/null || true) and explanatory comment per review feedback

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Copilot AI changed the title [WIP] Save shell history before terminating the distro on restart Save shell history before WSL termination on restart Feb 24, 2026
Copilot AI requested a review from crramirez February 24, 2026 19:39
@crramirez crramirez marked this pull request as ready for review February 24, 2026 19:45
Copilot AI review requested due to automatic review settings February 24, 2026 19:45
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request attempts to prevent shell history loss when WSL is terminated by the pengwin-setup script during restart scenarios. The change adds a history -a command before wsl.exe --terminate is executed to flush the bash history to disk.

Changes:

  • Added history -a command in bye_message() function before WSL termination in interactive mode

pengwin-setup Outdated
message --title "Setup is complete." --msgbox "This window will be closed to apply the changes in the environment.\nPlease start Pengwin again \n\nYou may rerun pengwin-setup any time by typing: $ pengwin-setup\n\nYou may open a browser link to get help any time by typing: $ pengwin-help" 14 80

if [[ ${#CMD_MENU_OPTIONS[*]} == 0 ]]; then #No automated installation
history -a
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When history -a is called from within the pengwin-setup script (a child bash process), it will only save the history of the script's own bash process, not the parent interactive shell's history that the user was working in before running pengwin-setup.

Since bash processes maintain separate in-memory history lists, calling history -a in a subprocess cannot affect the parent shell's history. When wsl.exe --terminate kills all processes, the parent shell's unsaved history will still be lost.

To actually save the user's shell history, you would need to execute history -a in the user's interactive shell before the script terminates WSL. This could be achieved by:

  1. Creating a wrapper function that users source into their shell
  2. Using a trap mechanism in the user's shell profile
  3. Documenting this limitation and advising users to periodically save their history with PROMPT_COMMAND or manual history -a calls

If this change was tested and confirmed to work, please provide details on the test scenario, as the current implementation appears to have this limitation based on standard bash behavior.

Copilot uses AI. Check for mistakes.
pengwin-setup Outdated
message --title "Setup is complete." --msgbox "This window will be closed to apply the changes in the environment.\nPlease start Pengwin again \n\nYou may rerun pengwin-setup any time by typing: $ pengwin-setup\n\nYou may open a browser link to get help any time by typing: $ pengwin-help" 14 80

if [[ ${#CMD_MENU_OPTIONS[*]} == 0 ]]; then #No automated installation
history -a
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling for the history -a command. While it rarely fails, if the history file is read-only or the filesystem is full, it could produce an error that would be displayed to the user just before WSL terminates. Consider using history -a 2>/dev/null or history -a || true to suppress any potential errors.

Additionally, add a comment explaining the purpose of this command to help future maintainers understand why history is being saved at this specific point.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in baffbc6 — added 2>/dev/null || true for error suppression and a comment explaining the purpose of the history -a call.

Co-authored-by: crramirez <8397379+crramirez@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants