Visual Studio Code terminal displaying "sh-3.2$" every time I "Open in Integrated Terminal" instead of the working directory name (Mac OS) - visual-studio-code

Earlier today I was having an issue where when I would go to open a new terminal or open a file or folder in Integrated Terminal the terminal would be automatically killed within a couple of seconds without me manually killing it. I was confused as to why this was happening because as far as I could tell I hadn't changed my settings.json file in VS Code or User or Workspace settings and everything was running smoothly just minutes earlier. I was able to resolve that issue but I created a new minor inconvenience. Now whenever I open a file or folder in Integrated terminal it displays "sh-3.2$" instead of the current directory I'm in. If I type pwd and press enter it'll of course display the current directory I'm in but I don't want to have to type that a million times moving forward. If somebody could help me fix this issue I'd greatly appreciate it! I read some of the documentation online but I'm a new bootcamp student and I tried following along but it was going over my head. Thanks again!
I was reading a similar Stack Overflow question and they were saying to try and setup/configure my bash shell to have a prompt with path, specifically the PS1 environment variable, but I was confused on how to actually go about doing that.

Related

VS Code Terminal command extra first letter

In vs code terminal I'm getting first letter of command twice. it's not causing any problem but it's kind of annoys me to watch the wrong command. I'm not writing any letter twice, the first letter of all commands gets repeated automatically.
as you can see there are 2 commands first one ppython first p automatically got repeated even though i wrote python it makes it ppython. and the first p that got repeated won't delete from there even if i spam backspace so many time . the I tried to clear the command till first p and as I'm not able to remove first p from terminal I just wrote ython in front of it. it looks proper now python. but I got a error response as ython is not recognized command. this same happens with other commands too like cd converts to ccd.
Edit : I Re-installed vs code then but that didn't resolved my problem, when I installed it again all my extensions were there already installed then I deleted vs code again then went to the vs code's location there was a folder name .vscode I deleted that then installed vs code again now all the extensions were deleted from vs code but I'm still having the main problem . that doesn't resolved it. and I'm not getting that error while using other terminals like git bash and I'm getting this error only when I open python file's folder not when I open a react app folder or normal js or other language.
I also tried reseting the default setting from setting.json file as one of the answers suggested but that doesn't worked.
It's hard to answer this without knowing your configuration. What plugins have you installed? Try disabling those related to the terminal emulator one by one to see if they're causing any issues.
In doing this, you would naturally restart the terminal emulator as well. If the problem persists, check if you get this erroneous doubling on a terminal emulator outside of VS Code (Terminal or PowerShell).
If nothing works, try reinstalling the interpreter and also VS Code. Especially the latter, if this seems to affect only the terminal emulator within VS Code.
It's really hard to answer your question without knowing your vs code configuration setting.
The easiest way is you can reset your vs code to default
The Steps
Go to View > Command Palette or press Cmd + Shift + P (macOS) or Ctrl + Shift + P (Windows).
Search for open settings json and select Preferences: Open Settings (JSON) which show ups from the result list.
If you’ve been working with VS Code for a while and installed a lot of things and made a lot of changes, you’ll find there’s a lot of stuff in this file:
Delete everything inside the root braces and save the file
Relaunch your VS Code.
(This step is optional) In case you want to not only reset VS Code but also remove all installed extensions:
Delete the ~/.vscode/extensions folder if you’re on a Mac.
Delete the %USERPROFILE%.vscode\extensions folder if you’re using Windows.

Renaming files doesn't take effect in VScode while using WSL2

I have a very annoying problem in my VScode setup.
I'm using WSL as a terminal to work on my projects and occasionally, mistype the name of one of the folder or file that I'm working with.
For example:
I accidentally created the Mainheader.js file in layout folder (without the capitalized L) therefore, I decided to rename the folder with a capital L.
Now on my React app, any changes made to MainHeader.js file will not be reflected. I did update the related import.
So I decided to delete the entire folder and recreate it with MainHeader.js but this is what I end up with.
The file is there in my folder but when I click on it, I get
"Unable to open Mainheader.js - File not found"
So I try to create it then I get this error:
Unable to create file 'wsl\path]to\MainHeader.js' that already exists when overwrite flag is not set
Has anyone run into this type of behavior in WSL before? It's quite annoying because the only workaround I've found so far is to create a completely different folder with a different name...
Any help would be appreciated. I can't really work like this.
I've been having the same problem for the past 2 days. I presume its a permissions issue, but unfortunately I don't know how to permanently fix it.
I did find this work-around though:
Open a new VS Code window. (I'd recommend closing any VS Code window that had
your project directory open.)
Create a duplicate or copy the contents of the problem file so you don't lose
your code.
Delete the problem file.
Now create the file again using VS Code. Go to File > New Text File. Next paste
in your code.
Now save your new file. Go to File > Save As and save your new file with at the same path + filename + extension that was giving you problems previously. VS Code should allow you to save the new file without any issue.
Now you can open this new VS Code window to your project directory and you should be able to continuing accessing the file that was a problem before.
Basically we just deleted the problem file and then created it again from scratch in a new VS Code window.
Hope this work-around works for you!
EDIT 09/20/2022
Following Baza86's answer here solved the issue for me. Seems like it was a permissions issue of sorts, but if you use the Remote-WSL extension VS code can directly access the linux filesystem.
How to run VScode in sudo mode in WSL2?
You may need add the case option to you options in the wsl config. The default is set to off, however you can set this to off, dir or force.
Open your wsl.conf using sudo with any text editor while running window subsystem Linux. The config file resides in /etc/wsl.conf. This file is used to configure settings per-distribution for Linux distros running on WSL 1 or WSL 2.
My default config looked like this yours may be different:
[automount]
options = "metadata"
add
[automount]
options = "metadata,case=dir"
Here is the official Microsoft docs for Advanced settings configuration in WSL - https://learn.microsoft.com/en-us/windows/wsl/wsl-config

What settings do I have to change to make Visual Studio Code automatically run files in the right directory?

Coming from IDLE, I am used to be able to just left-click python files anywhere, it'll launch IDLE, and then pressing F5 just runs the script. In VSCode however, I have to open the terminal, cd into the right directory, and only then can I finally run my python script. Is there a way to change this behavior?
I was recommended to use the Code Runner extention and bound the Run Code (code-runner.run) command to my F5 key.
Then I noticed input() not being ran so I had to make sure code-runner.runInTerminal was on, but that re-started my problem from the beginning because the terminal was at the wrong working directory and then I finally found the code-runner.fileDirectoryAsCwd setting to run it from there.
I think this solution is similar to this one for the python extention, but I'm not sure if that would cause the whole wrong working directory issue again.
choose from menu file then click on auto save

Cannot delete folder in Visual Studio Code definitely

I deleted a folder in Visual Studio Code to recreate it. But each time it recovers all files whereas I just want to create a new empty folder with same name.
This is a common issue that I am also facing for more then a year now and I am unable to find an open issue about this on Github. Every issue related to this that is opened gets closed because the developers are unable to find the source of the problem.
One way I could sometimes replicate the issue is to:
Open the project folder in Windows Explorer
Search for something inside VSCode that is contained in the folder
you are going to delete.
Try to delete the folder in VSCode.
Folder is not deleted.
Clearing the search after does not solve the issue. Most of the times I have to close and reopen VSCode.
Another ridiculous part is that the VSCode sends the file to the OS Trash and you are unable to undo the deletion when it works (CRTL + Z). VSCode is being pushed to the community by many developers but is really an infant editing tool that is terrible, the only amazing part of it is the huge ammount of plugins.
This is a long lasting bug that occurs ALL THE TIME with me. I know this is not a valid answer, but it's what I know about this problem this far.
i had the same problem. But works turn off malwarebytes. Maybe another antivirus is blocking to delete folders to, try this.
Try running Visual Studio in Administrator mode. It worked for me.
It took 6 hours to find out that.... it can be deleted by VsCode file explorer, if i try to delete it manually it juggles with admin permission and user permission back and fourth.
Just delete the folder from VSCODE file explorer from the left menu.
I just restart my mac and everything went well after that 🤞
i had the same problem. I go to Terminal and turn off all powershell,a voala I finally can delete folder from VS explorer.

Editing WSL config files\code etc with Visual Studio Code, in Windows

I am really enjoying WSL and using it for a lot of stuff these days, including my Ansible workstation, also writing a lot more code in it...
Question: I can see where the WSL file system is:
https://askubuntu.com/questions/759880/where-is-the-ubuntu-file-system-root-directory-in-windows-nt-subsystem-and-vice
All of the docs tell you very clearly to stay away from the Linux file system and not to access it from the Windows instance it is running under. Fine. But! I hate to ask redundant question, but I would dearly, dearly love to be able to use full blown graphical VS Code in Windows in my text editor for WSL. Am i missing a trick somewhere for a way to do this without breaking anything?
Apologies for the non question. Hopefully it is allowed.
In vscode...
You can press the green icon bottom-left
This will open the command palette
Choose "New WSL Window"
Open a folder, you will be able to navigate from ~ to choose location in command palette
Once folder is choosen, you're set to go, vscode will display file tree from opened folder and you can do your thing :)