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

Save terminal commands history #85831

Closed
LucaGabi opened this issue Nov 29, 2019 · 15 comments
Closed

Save terminal commands history #85831

LucaGabi opened this issue Nov 29, 2019 · 15 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug terminal Integrated terminal issues windows VS Code on Windows issues
Milestone

Comments

@LucaGabi
Copy link

Save gitbash terminal commands history on vscode exit for future sessions.

(using windows 10 it's not available)

@vscodebot vscodebot bot added the terminal Integrated terminal issues label Nov 29, 2019
@Tyriar Tyriar added bug Issue identified by VS Code Team member as probable bug windows VS Code on Windows issues labels Dec 30, 2019
@Tyriar
Copy link
Member

Tyriar commented Dec 30, 2019

This is maybe happening because of how we're killing/cleaning up the process?

Not confirmed but I've seen plenty of reports for this on Windows.

@Tyriar Tyriar added this to the Backlog milestone Dec 30, 2019
@Tyriar Tyriar added the help wanted Issues identified as good community contribution opportunities label Dec 30, 2019
@blueworrybear
Copy link
Contributor

Hi, I have encountered this issue too. After studying, it seems to me that it's because how node-pty kill process.

At windowsTerminal.ts:161

public kill(signal?: string): void {
    this._defer(() => {
      if (signal) {
        throw new Error('Signals not supported on windows.');
      }
      this._close();
      this._agent.kill();
    });
  }

The process is force killed, therefore the shell terminates immediately and does not save history.

The possible solutions IMO may be:

  1. Users set PROMPT_COMMAND="history -a" by themselves.

    This is what I do for short-term solution.

  2. Send a exit command before pty killed.

    Maybe add below code:
    terminalProcess.ts:190

    try {
    	if (this._ptyProcess) {
    		this._logService.trace('IPty#kill');
    		this._ptyProcess.write('exit\r\n');
    		this._ptyProcess.kill();
    	}
    } catch (ex) {
    	// Swallow, the pty has already been killed
    }

    Not sure it's an acceptable way to solve this problem. 🤔

Please let me know what you think. I would like to solve this issue.

@Tyriar
Copy link
Member

Tyriar commented Feb 8, 2020

@blueworrybear writing exit won't be good enough as there may not be enough time to exit gracefully before kill anyway (a race condition) and also exit\r\n might not do anything depending on the state of the terminal. What we really need is a way to signal the process to shutdown gracefully and kill it forcefully if it didn't happen several seconds later. Something like this but it would be better if there was a node.js API to do it (even if we need to go to C++): https://stackoverflow.com/a/6860723/1156119

@blueworrybear
Copy link
Contributor

@Tyriar you are right. Sending exit\r\n is not a good idea. My first thought is to graceful kill the process. However, I found that I am unable to graceful kill bash with taskkill. I got an error message when I tried taskkill /PID <pid>. It said the process could be killed only with /F option. I am still looking for the solution. 😕

@SterlingButters
Copy link

@Tyriar @blueworrybear And does PROMPT_COMMAND="history -a" have any obvious disadvantages?

@jerrygreen
Copy link

I have this problem on windows, but I don't have it on macos

It seems nobody's using VSCode on windows?

@Tyriar
Copy link
Member

Tyriar commented Oct 11, 2021

I don't think this is actionable so closing off.

@LucaGabi
Copy link
Author

LucaGabi commented Oct 11, 2021

I don't think this is actionable so closing off.

.. can't be solved ?

@jerrygreen
Copy link

I guess mister @Tyriar doesn’t understand the problem, or can’t reproduce it, so [he thinks] he’s reasonably closing it.

As for myself, after when I’ve put export PROMPT_COMMAND="history -a" into one of my rc files, I kinda forgot about this problem, even though it was said it is a short term solution, - by @blueworrybear, this simple fix kinda works good long-term, negating this VSCode bug.

@Tyriar
Copy link
Member

Tyriar commented Oct 12, 2021

@jerrygreen if you would like to enlighten me on a proper solution for this I'm all ears, modifying someone's rc file is not an acceptable fix because it would be too invasive.

@jerrygreen
Copy link

So, at least, you admit there is such an issue... So why closing?

@Tyriar
Copy link
Member

Tyriar commented Oct 12, 2021

Because we're currently doing issue grooming to keep our issue count manageable, you can read about the process in #134730 and https://github.com/microsoft/vscode/wiki/Issue-Grooming

@jerrygreen
Copy link

jerrygreen commented Oct 13, 2021

Let me remind you again, this issue is related to Windows-users only. I wasn’t able to reproduce it on either macOS or Linux. Means that all the [countless] people that are just starting to use VSCode on Windows, newbies, - they will face this problem. If they had macOS, or Linux, they wouldn’t have such an issue, so closing this issue supports this idea:

«If you want to code, don’t use Windows. Use Linux or macOS»

This idea is in perception of people for a long time already. And Microsoft tries to fight that. I appreciate it.

But what you did here, - is the otherwise. I don’t think this is what Microsoft would like.

P.S. Well might be it’s not an issue of VSCode, but Windows itself, i.e. not your work. Do you confirm that? We can report a problem using Windows Feedback.

@Lemmingh
Copy link
Contributor

This is a limitation of Git Bash itself. I'd recommend Ctrl+D every time you quit a Git Bash session and not relying on Mintty's behavior.

If you have ever taken a look into Git Bash's processes, you will also find it unlikely to be a Windows problem.

When you run Git Bash from Start Menu (git-bash.exe). You get a login shell run by Mintty. Mintty performs logout for you when you close its window.

When you run Git Bash in VS Code (bash.exe), however, there is no Mintty, no sugar. You should either

  • Log out on your own.

or

@Tyriar
Copy link
Member

Tyriar commented Oct 14, 2021

@Lemmingh thanks for the info, I'll add this to the terminal docs FAQ page

@Tyriar Tyriar reopened this Oct 14, 2021
@Tyriar Tyriar removed help wanted Issues identified as good community contribution opportunities wont-fix labels Oct 14, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2021
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 terminal Integrated terminal issues windows VS Code on Windows issues
Projects
None yet
Development

No branches or pull requests

6 participants