Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running Commands in VS Code Terminal does not save the history #181508

Closed
shalearkane opened this issue May 4, 2023 · 8 comments · Fixed by #182904
Closed

Running Commands in VS Code Terminal does not save the history #181508

shalearkane opened this issue May 4, 2023 · 8 comments · Fixed by #182904
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders linux Issues with VS Code on Linux macos Issues with VS Code on MAC/OS X terminal-process Problems launching processes, managing ptys, exiting, process leaks, etc. verified Verification succeeded
Milestone

Comments

@shalearkane
Copy link

Running commands in a normal bash terminal retains the history (of the commands ran) but the same is not true for VS Code. So after closing VSCode all of the command history is deleted and the user has to remember any complex command that they ran. Ideally we would want our history to be stored in .bash_history or if VS Code doesn't want to touch user files, in .vscode_bash_history perhaps?

@meganrogge
Copy link
Contributor

This works for me

@hameer-spire
Copy link

Doesn't work for me either, tried deleting $HOME/.vscode-server and re-installing, no dice.

@meganrogge
Copy link
Contributor

Maybe this is a remote issue

@Tyriar
Copy link
Member

Tyriar commented May 12, 2023

More reports here: #180474

@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug remote Remote system operations issues terminal-process Problems launching processes, managing ptys, exiting, process leaks, etc. labels May 12, 2023
@Tyriar Tyriar modified the milestone: May 2023 May 12, 2023
@vaindil
Copy link

vaindil commented May 12, 2023

This affects me on my MacBook Pro as well. It's a problem 100% of the time, it's not intermittent. I'm guessing it's not a remote issue, as it happens when I'm using a completely local folder without any sort of remote functionality. There are several other reports of this issue in #180474 as well.

If I type exit to close the terminal before I quit VS Code, the history is saved like it should be. If I quit VS Code without doing that, the history is lost. This is a recent issue (within the last couple of months or so), it used to work correctly. Happy to provide any other info that can help diagnose this, as I can always reproduce it.

@Tyriar Tyriar added macos Issues with VS Code on MAC/OS X linux Issues with VS Code on Linux and removed remote Remote system operations issues labels May 12, 2023
@shalearkane
Copy link
Author

Yes, the history save feature works if I type exit or ctrl+D to close the terminal. Doing it by any other way (like clicking the trash button to close the terminal) does not save the history.

@shalearkane
Copy link
Author

shalearkane commented May 13, 2023

I think that I have found the issue.

this._ptyProcess.kill(!isWindows ? 'SIGKILL' : undefined);

In this line, we are sending SIGKILL instead of SIGTERM, hence the process gets killed without the chance to write the history to the file (source)

However it seems that this change was made because the terminal subprocess (running shellIntegration-bash.sh) couldn't be killed because the traps are also gobbling up any signal. Hence this issue #176819

I think the solution to this can be done by creating a function something like :

cleanup() {
    err=$?
    trap '' EXIT INT TERM
    exit $err 
}
sig_cleanup() {
    trap '' EXIT
    false # sets $?
    cleanup
}

trap sig_cleanup TERM

(relevant discussion in SO)
That way, the SIGTERM signal can be intercepted and exited as needed.

@shalearkane
Copy link
Author

shalearkane commented May 13, 2023

If it is possible, could you help me to write a patch to fix this issue? 😄 I have tried patching the __vsc_get_trap() function in the file src/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh to trap SIGTERM however, I am having trouble getting it to work.

@meganrogge meganrogge added this to the May 2023 milestone May 18, 2023
@vscodenpa vscodenpa added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels May 18, 2023
@DonJayamanne DonJayamanne added the verified Verification succeeded label Jun 1, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug insiders-released Patch has been released in VS Code Insiders linux Issues with VS Code on Linux macos Issues with VS Code on MAC/OS X terminal-process Problems launching processes, managing ptys, exiting, process leaks, etc. verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants