powershell in vscode pastes clipboard content on pressing 'w' - powershell

I'm not sure how that happened. I tried to create script, to work with some legacy solutions:
#!/bin/bash
echo "Enter pass"
stty -echo
trap 'stty echo' EXIT
read pass
stty echo
trap - EXIT
echo "Nice!"
command="
cd /home/user/work_dir &&
export GIT_PASSWORD=${pass} &&
do_some_stuff
"
ssh root#some_host ${command}
Unfortunately, I had to pass password through environment variable. I only hoped that shell with that variable will not live long. Also I wanted to execute this script like VS Code Task like this:
"tasks": [
{
"label": "Do_stuff",
"type": "shell",
"command": "${workspaceFolder}\\.vscode\\do_stuff.sh"
}
]
And I've achieved some success. BUT, now every time I hit 'w' key in VSCode powershell, instead of printing 'w', it pastes the content of clipboard. I tried to restart shell, restart VSCode and restart whole computer. Also, Windows powershell outside of VSCode works just fine.
Now when I need to work there, I copy 'w' symbol into clipboard, but it would be nice to have more permanent solution.

As Theo pointed out, my key mapping was messed up. I deleted that particular mapping and now everything works just fine, though how that happened is still a mystery. My best guess is that new mapping was added to VSCode (inseders) in the last update. But I failed to find any evidence in release notes.

Related

Weird CMD - VSCode behavior

yesterday I had SumatraPDF and VisualStudioCode with latex-workshop working with forward and reverse-search. Today the reverse-search didn't work any more. With a simple bat file I tried to show the commandline arguments.
echo %*
pause
They seemed correct and when I copied the command and paste it into a new cmd it works. To do further testing I tried to direct command and run it.
"C:\....\Code.exe" -g "%1:%2"
pause
Visual Studio Code responds: bad option -g
In SumatraPDF I set cmd as command.
Now the behavior is that I have two cmd windows. With the cmd directly opened the VSC open's the file. With the cmd launched indirect I got the error message.
I have tried resetting the environment variables, changing the current working directory, and checking the code page currently in use.
How can it be that cmd behaves differently with seemingly the same environment? And what can I do to make a cmd started from an application work like a cmd started by windows?
Update: It appears there were a couple of recent security changes in the way VSCODE.exe is allowed to interact with the command line (especially affecting LaTeX-workshop users) so for recent changes twice this year see the discussion at https://forum.sumatrapdfreader.org/t/inverse-search-not-performed-for-vs-code-exe/4486/27
Within SumatraPDF the reverse syntex command for %1 is replaced by %f for file and (l)L for line
It is triggered by a double click near the line of interest and if the synctex index file was compiled correctly by PdfLaTeX (or similar) it will include the tex %f(ilename) and the nearest %l(ine) reference to the point where double clicked.
Thus your tex syctex enhanced "reverse search" call out of SumatraPDF should historically be
"C:\...path to...\Code.exe" -g "%f:%l"
that's Lower L not 1
Avoid using any depreciated -inverse-search parameter from a LaTeX editor just add it once into SumatraPDF-settings.txt and then it's not disturbed by repeated assignments when running your -forward-search.
It will NOT work if the file.synctex or file.synctex.gz is corrupt by a bad PDF compilation.
HOWEVER It seem Microsoft have added the requirement to add a CLI.js handler and requires another switch setting after that ! (see link to discussion in Update above)
For a small test file download https://github.com/GitHubRulesOK/MyNotes/raw/master/AppNotes/SumatraPDF/LATeX%20and%20Reverse-Search.zip unpack and open sync.pdf in SumatraPDF to test that double click on page opens sync.tex in the editor
If the message is cannot start ... then the command line is not configured correctly. A rough test for a bad synctex is to see what happens if the call is changed by adding cmd /k echo to the start, since that will confirm the reverse command. Here I wrote "wrong" as the path to code.exe, once corrected I can remove cmd /k echo.
For some other systems where the reverse might change
see https://github.com/sumatrapdfreader/sumatrapdf/issues/1197#
However there should be no interference in a valid VsCode call.

VSCode task in WSL environment, terminal keeps exiting when trying to run shell script

NOTE
I've had to remove like two chunks of this post because stack overflow kept interpreting it as code when it isn't and it wouldn't let me post, I'll just make a screenshot of what the post is supposed to look like and post it here. Read this instead.
Summary
I was finally trying to learn how to use VSCode tasks and so I copied the first task example from here and created a shell script at scripts/test.sh which contains simply "echo foo". I also commented out the windows alternative script because I exclusively use WSL/Bash. Whenever I run the task I receive a "The terminal process terminated with exit code: 1" error message, which is no help whatsoever.
Testing
I ran various tests and I have no idea why this isn't working.
Proving The Task Is In The Correct Directory & In WSL
First I thought maybe the task isn't running in WSL or that the directories are out of sync, so I changed the commands to see what happens.
First, I changed it to:
"command": "pwd",
and the output was "/mnt/f/.../.../tmp/tmp.1BitOIA78E" (... are for some arbitrary path) so clearly I concluded I was running on WSL and in the right path.
Proving the Script is Executeable
Next I thought, maybe the script I'm trying to run isn't executable or something to that affect, so I changed the command to:
"command": "stat ./scripts/test.sh",
and I got the following output which shows, the file exists, it's executeable & can be accessed through "./scripts/test.sh" from whatever directory the Task is set to on construction
I run the task by typing ctrl-shift-P to open the menu, select "run tasks" and then select 'My First Task'.
Note: I don't think this is a settings problem. There're no workspace settings setup (because this is just me testing) & just in case, you can find my current user settings here which I updated immediately before posting this.
Expectations
What I'd like is either:
Someone to tell me how I can access the stderr and stdout log of the shell upon startup so I can get some actually helpful information as to why this is happening.
Someone to tell me why I can run a script perfectly fine outside of a task, but within a task it completely fails.
Whats also of note is that the script isn't the problem here. Leaving it completely blank, doesn't stop the terminal from straight up crashing.

Ctrl+c not working in integrated terminal which uses Powershell

I'm using Powershell in the integrated terminal by adding the following line to the settings.json file.
"terminal.integrated.shell.windows": "C:\\WINDOWS\\system32\\WindowsPowershell\\v1.0\\powershell.exe",
It works very well, but usually, when I'm in Powershell, typing ctrl+c cancels what I had typed and opens a new line.
But in the integrated terminal it just prints ^C.
Is there a way to fix it or find an alternative method to achieve this?
Thanks
This is with VSCode and not necessarily with the PowerShell Extension. You can see this by just using the default cmd.exe terminal, CTRL+C does nothing. It does not print the ^C at all, and creates no new line.
If you want this to work as expected in the normal command prompt or PowerShell.exe you will need to submit an issue to VSCode repository and request it.
I would expect this is all tied to the keybindings.json file. I went through that file but could not find a command available to the same function that occurs in the full command prompt or console. So this will likely need a new command added for VSCode.
If you search through the keybindings file you can see the terminal has that key CTRL+C bound to copySelection when terminalFocus && terminalTextSelected. This is why the ^C is being output, and no new line is being added.
A workaround:
Pressing Esc will erase the line back to the beginning.

Sublime Text build system generates [WinError 6] The handle is invalid error

I'm attempting to create a Sublime Text 3 build system to render and Asciidoc-formatted document using AsciiDoctor.
AsciiDoc.sublime-build:
{
"cmd": ["asciidoctor","$file"],
"selector": "source.asciidoc"
}
When I execute the build Ctrl+B, I get an error:
[WinError 6] The handle is invalid
[cmd: ['asciidoctor', 'C:\\Users\\XXXX\\Desktop\\hello\\hello.asc']]
[dir: C:\Users\XXXX\Desktop\hello]
[path: c:\tools\ruby193\bin\asciidoctor]
[Finished]
I'm able to successfully render the document via the Windows Command Processor, the PowerShell, and the Ruby prompt.
This build script leads to the same error:
{
"cmd": ["asciidoctor","$file"],
"path": "c:\\tools\\ruby193\\bin\\asciidoctor",
"shell": true,
"selector": "source.asciidoc"
}
What am I missing?
Found a solution: Build system: "The handle is invalid".
The final response:
by showka on Sun Oct 02, 2011 7:34 pm
Thank you very much, launching Sublime Text outside of the command prompt gets rid of this problem.
I've tried setting PYTHONPATH to run from the prompt but that won't fix it. My command prompt has so much goo in the environment
variables I'm sure something else is tripping it up as well. :) For
now I'll just make a second batch file to launch Sublime with certain
programs added to the path.
...
UPDATE: I found the issue and can now run it from my command prompt.
Here's how my batch file used to look:
Code: Select all
SET PYTHONPATH=START "Sublime Text 2" /B "C:\Program Files\Sublime Text 2\sublime_text.exe" %*
The /B option was messing it up for some reason. Normally I need that
to keep the command prompt from waiting for the launched program to
exit, but with Sublime its unnecessary for some reason. Taking the
option off made it work.

Is there any way to automatically save command history to a file in cmd.exe, similar to bash's bash_history?

I am aware that one can do
doskey /history
to save the command history at a particular point in time, but I wonder if there's a way to proactively save command history to a file, as the commands are being issued.
Once a command prompt is closed, the history is lost, so it's easy to accidentally close a command prompt when one is done.
I'd like to be able to say something like:
log Commands.log
and then issue my commands, and have the commands be saved to Commands.log.
You could create a doskey macro to remap the EXIT command, as follows:
doskey exit=doskey/history$g$gc:\temp\commands.log$texit $1 $2
This would append the contents of your command history into a file named "c:\temp\commands.log" each time you exit the prompt by typing "exit".
CAUTION: I haven't tested potential side effects of using this with EXIT's "/B exitCode" parameters, but there shouldn't be any since you're capturing the parameters with "$1 $2" anyway.
This doesn't do exactly what you're looking for, but it does capture your command history as long as you exit using EXIT (vs. just closing the window).
More info and samples on DOSKEY macros are here:
http://technet.microsoft.com/en-us/library/bb490894.aspx
I know it is late but I can see two alternatives.
Firt clink or something more complete that include cmder
Each time you will open cmd it will be clink and it works great
As Novy has already said, try Clink; but also use the following link so it also works in admin mode.
run cmd with clink as administrator in windows to save your command history permanently