Weird cases when drag and droping files in to vscode terminal - visual-studio-code

My problem
I am currently working with Python in VS Code and I encountered a weird problem with the drag and drop feature. When I drag a folder path or a file path into the Terminal, then it always begins with the &
sign. This only happens when I start my program.
Here is an example:
& 'filepath' or
& "filepath"
I don't have a problem with the quotes but with the & and the blankspace. I can't find anything online, I was wondering if anybody else has this problem.
Thanks in advance :)
What did you try and what were you expecting?
Well, I did try it with other files and folders, but it didn't help.
I've also tried running the code outside VS Code and drag and dropping was fine. So I guess it has something to do with VS Code.

This happens in certain conditions when the path contains a space or parenthesis and the current terminal is powershell based.
I'm not sure why this was added, but the mechanism happens here:
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts:2664
if (isPowerShell && (hasSpace || originalPath.indexOf('\'') !== -1)) {
return `& '${originalPath.replace(/'/g, '\'\'')}'`;
}
if (hasParens && isPowerShell) {
return `& '${originalPath}'`;
}
The original PRs introducing this change are here and here
The rationale seems to be to run files with certain symbols in their name:
single quotes in paths for PowerShell (i.e /Users/tyler/tyler's stuff/ -> & '/Users/tyler/tyler''s stuff/' to escape a ' in a ' ' string, you add an extra ')
The smallest workaround is to not open a powershell terminal.
So either open a terminal with the drop-down next to the "+" (#command:workbench.action.terminal.newWithProfile) which should have other entries next to powershell like "Command Prompt"(cmd.exe).
If you want to make this the default select the terminal profile then use the "Terminal: Select Default Profile"
(#command:workbench.action.terminal.selectDefaultShell) command to change the default.
If you want this to be configurable or not happen when the foreground application is no longer powershell you should probably file an issue with vscode.

Related

Sublime fails to open new_file in macro

In Sublime (Version 3.2.2, Build 3211) (Ubuntu 18.04.5), I'd like to record a macro where I select-all, copy and paste the current content into another, unsaved file. And then do other commands as well, but I'm not even getting that far. The new-file step doesn't seem to work – neither new, nor new_window, newWindow, new_file, newFile seem to work; not even reopen_last_file. It should be new_file, though.
The console throws this:
Unknown macro command new_file
Which is weird. The command new_file works fine in other contexts: looking at the key-bindings settings, ctrl+n is bound to the same command and the hotkey has no issues.
Selecting all, copying – even this following bit works as intended:
{
"command": "insert",
"args": {"characters": "Hello, Friend!\n"}
}
In their forums, user "jps" writes:
With regards to the other console messages (unknown command, etc), don’t worry about them, they’re supposed to be there :slight_smile:
… but this doesn't seem to be right if it's obviously not working.
I have a project open but closing the project has no effect.
Is there maybe a package or something missing?
Macros in sublime can only capture and replay TextCommand commands; that is, commands that directly modify the content of a buffer or it's visual state. Examples including adding or removing text, changing the selection, moving the cursor around or changing view specific settings (like toggling word wrap or changing rulers, etc).
Commands like new_file, new_window or opening and closing projects are WindowCommand commands, which can't be captured via a macro.
In order to run a sequence of commands that includes a WindowCommand (or ApplicationCommand), you need to use a package. Two examples of that which are readily available on Package Control are Chain of Command and Multicommand.

Powershell profile, dynamic prompt and ansi color escape codes being reset after git has executed

I am trying to duplicate my cmder dynamic prompt inside Powershell.
This dynamic prompt uses a combination of some specific unicode characters and background and foreground colors to produce a prompt that can contain items, such as:
Current directory (white on blue)
Current git branch (black on green)
Ahead/behind (black on yellow or white)
Special status (merge, rebase, etc. - black on red)
The cmder prompt works wonders, and I've managed to reproduce most, if not all, of it using a Microsoft.Powershell_profile.ps1 script with code.
However, after running some git commands, like git pull, the powershell prompt becomes messed up. The symptoms are that handling of those escape codes are suddenly turned off. This does not happen if I only use cmder.
Example:
The top git lg (git log on one line, decorated) command is running from cmder, notice that the prompt comes back with colors.
Then I switch to powershell right above the middle, notice I got the same looking prompt there, only this is produced from the powershell profile script.
However, after running git lg once again, only now from Powershell, the handling of the escape codes are disabled and the prompt now becomes totally messed up.
My question is:
Is there anything I can do in the powershell profile to enable this before producing the prompt, or to prevent this from happening?
Here is a very simple powershell profile file:
function prompt {
"" + [char]0x001b + "[39;44mTEST" + [char]0x001b + "[0m" + [char]0x000a + "> "
}
Simply drop this into a file named as:
C:\Users\<USERNAME>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
(make sure to make a backup of the file if it already exists!)
Then start Powershell and you should be able to reproduce this:
Notice that last line before the prompt there contains the escape codes verbatim.
Things I've tried:
Outputting ESC c: Resets the device to its original state. (no apparent effect or change)
Running Powershell directly (not from within cmder), this works exactly the same as above, only the Windows has different initial colors, such as a blue background. The coloring of my prompt seems to work fine, the special characters doesn't though but that's to be expected (the branch symbol and that triangle), but after git lg, still messed up.

How to tweak VSCode support for PowerShell - for better handling the typing of quotation marks

Is there a way to have VSCode handle the typing of the quotation marks when editing PowerShell as it handles that in JavaScript? When I type a single " I got it suffixed with another. This is OK. however, when the caret is at the end of the string just before the closing " - typing another "
will jump past the quote sign in JavaScript (this is the desired as it messes less with muscle memory)
will insert a new pair of quote sign in PowerShell..
Go to the installation folder of Visual Studio Code and open the
powershell plugin folder. On Windows it's
C:\Users\XXX\AppData\Local\Code\app-0.X.X\resources\app\plugins\vs.language.powershell
Open the file powershellDef.js
Search for autoClosingPairs
Add the pair for " to its value. The code line should look like this now:
autoClosingPairs: [['{', '}'], ['[', ']'], ['(', ')'], ['"', '"']],
Restart Visual Studio Code
Now it handles " in Powershell files the same way as it does in Javascript files.

editing objects from MongoDB with an external editor doesn't update the object

I'm using the Mongo shell. I've set my EDITOR to my notepad++ path. I create an object and then I use the EDIT command to edit the obeject using notepad++ but it doesn't update the object.
// mongo shell
var pow = { name: "teest" };
edit pow
// notepad++ opens a document called 'mongo_edit141225123.js' that resides
// in C:\users\...\Appdata\local\temp
// I edit the object, save and close notepad++
pow // object isn't updated :(
what am I missing?
There seem to be a few caveats here. But I can describe how I got this working:
Set the PATH environment variable to include the path to the notepad++ executable. Note to both "apply" this change and not have an existing command line window when doing so. Or at least open a new one once this step is complete.
Specify an EDITOR variable in your command shell window, or otherwise set that under the same system properties as setting the PATH environment variable. Since the program directory is in the PATH just set the executable name:
set EDITOR="notepad++"
Launch your mongo shell and go to edit a variable:
> edit something
This will launch the specified editor, with an "undefined" variable at first. Type in something "valid", as any invalid JavaScript declaration will be discarded. Now for the important part. After your edit and when "closing" click the "tab close" icon and do not close the entire editor as shown:
That last part seems to be the most important. If you are prompted to save (and you likely will be ) then do so. Only "after" the tab has been closed (and saved) should you then close the editor itself.
If you then subsequently issue the same edit something from the mongo shell, then the editor will open with the content that you edited before.
If you don't follow this and just close the editor window first, then you should see an additional tab opened and the original tab with the content that you had before. But subsequent changes will be lost as the shell is now tracking a different temporary file.
So follow those steps and you should be right. I would expect there are similar issues with other external editors that will actually resolve in a similar way.

How to view content of emacs autosave file

How do I directly see the content of an emacs autosave file, without implementing a file recovery operation?
That is, suppose I created a file with 'emacs foo', then emacs crashed, so I'm left with no file named 'foo' (since it never was saved) but with a file '#foo#'. When I type 'more #foo#', I get "Missing filename", as though the more command doesn't even see the #foo# part of the command.
I just want to see the text in #foo# so I can copy it out by hand without risking something going wrong in the file recovery process (eg #foo# getting overwritten by a new autosave operation).
(I'm using Terminal on OSX.)
Bash or another shell use '#' as comment character, try :
more "#foo#"