How to load .bashrc when using wsl interoperability? - powershell

I've downloaded neovim 5.1 and made a symlink to it in .local/bin folder.
After that I've added it to $PATH through .bashrc and aliased to vim:
alias vim="nvim"
export PATH=$HOME/.local/bin:$PATH
If I use vim command from inside the wsl I successfully launch neovim 5.1. However if I instead try to launch vim from powershell (wsl vim) .bashrc is ignored and vim 8.1 is launched instead. How can I make Powershell to use .bashrc in interoperability mode?

wsl bash -ic vim
-i tells bash that the shell is interactive, which causes ~/.bashrc to be loaded.
-c cause the next argument to be executed as a command(s); it also causes the bash process to exit after command execution.

Related

Looking for help on setting up wsl in vscode terminal

If I'm in my terminal and open a file with the code command, vscode will launch and the terminal inside code will show my full zsh setup that I have configured in hyper terminal. But if I open up code through windows, and select wsl as my default shell, it's pretty much useless. Anything I try, like sudo, git, apt, etc will return a command not found message.
So if I want to commit any changes in the terminal inside code then I have to use the git bash shell. Is it possible to get my zsh working without first launching from my terminal emulator so I'm using wsl instead of git bash?
running wslconfig.exe /list in powershell showed me that WSL was set to docker as the default shell, so then running wslconfig.exe /setdefault "Ubuntu" in powershell fixed my problem.

How to use Python3 on the VScode terminal?

Is there a way to force VS Code to use only python3? It always defaults to python2.7 no matter what I try. I've tried selecting the correct interpreter as python3.7. When I open up terminal, it immediately uses python2.7, In the settings it is pointing at 3.7, but the built in terminal which is nice, always defaults to 2.7.
First, understand that the integrated terminal of VSCode, by default, uses the same environment as the Terminal app on Mac.
The shell used defaults to $SHELL on Linux and macOS, PowerShell on
Windows 10 and cmd.exe on earlier versions of Windows. These can be
overridden manually by setting terminal.integrated.shell.* in user
settings.
The default $SHELL on Mac is /bin/bash which uses python for Python2.7. So VS Code will just use the same python to mean Python2.7. When you open a bash shell, it will load your ~/.bash_profile to apply custom aliases and other configurations you added into it.
One solution to your problem is edit your ~/.bash_profile to alias python to python3. But I do not recommend this because this affects all your bash sessions, even those outside of VS Code. This can lead to nasty side effects when you run scripts that need python to be the system Python2.7.
You can instead configure VSCode to load its own aliases, for its own integrated terminal. First, create a file named vscode.bash_profile in your home directory:
$ cat ~/vscode.bash_profile
alias python=$(which python3)
On my env, python3 is Python3.7. You can set it to the what's applicable on your env (ex. maybe python3.7). Then, in VS Code, look for the Terminal shell args setting:
and then open your settings.json and add these lines:
"terminal.integrated.shellArgs.osx": [
"--init-file",
"~/vscode.bash_profile",
]
Finally, restart VS Code. The next time you open the VS Code terminal, python should now be using your Python 3 installation. This should not affect your bash session outside of VS Code.
Note that, if you have some custom settings from the default ~/.bash_profile, you may want to copy it over to your ~/vscode.bash_profile, so that you can still use it on VS Code (ex. changes to PATH, git-completion scripts..).

Why working permanent alias in hyper terminal doesn't work in vs-code bash terminal?

I'm on Windows 10 machine and I just installed VS-Code to use instead of Atom. I tried to use permanent alias in VS-Code Bash Terminal which I had created & was working fine in Hyper Terminal, but it doesn't work in VS-Code terminal. Why is that & How can I fix it ?
I have
alias mongod="/c/Program\ files/MongoDB/Server/4.0/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/Server/4.0/bin/mongo.exe"
in my '.bash_profile' file
In VS-Code terminal, try and check your alias is still defined:
alias mongod
cd ~
more .bash_profile
You will then see if said alias is still there in that VSCode environment.
If it is: do a source ~/.bash_profile, and the alias should be operational.
see also "Why ~/.bash_profile is not getting sourced when opening a terminal?"
~/.bash_profile is only sourced by bash when started in interactive login mode.
When you open a terminal, the terminal starts bash in (non-login) interactive mode, which means it will source ~/.bashrc.
So in your case, move those alias definitions to ~/.bashrc.

Configure Eclipse to use bash login shell for Cygwin toolchain

I have a custom Makefile project in Eclipse and although the build does get run in a Cygwin shell... it does not seem to be a login shell (bash --login) as it doesn't set my environment variables like running cygwin.bat does.
Where in Eclipse can I change the shell command so that it will be a login shell?
What you actually aim with bash --login are your settings from /etc/profile.
Under UNIX you normally have only one login shell and so these settings are inherited by all other shells. Under Windows any Bash window is an isoloated login shell, which leads to missing environment settings when running Bash from tools that run bash simply as command processor.
I had a similar problem with Emacs compile feature. The best solution under Windows is to set the environment variable BASH_ENV to a script. Bash will execute this script when started without -i or --login, so that /etc/profile is not run. Hence the script will setup Bash for non-interactive, non-login shells.
Example:
BASH_ENV=%USERPROFILE%\.bash_env
as user environment variable. The least thing to do in this script is to set PATH as in /etc/profile:
PATH="/usr/local/bin:/usr/bin:${PATH}"
Check the path-settings in /etc/profile as it is created by Cygwin's setup.exe. You may also copy settings from ~/.bashrc or source this script.
Hope this helps.

How to get Powershell to run SH scripts

Can someone please tell me how I get Powershell to run .sh scripts? It keeps just trying to open the file i need in Notepad when I run this command:
.\update-version.sh 123
I've added .SH to my PATHEXT environment variable and also added the Microsoft.PowerShell_profile.ps1 directory to the Path environment variable.
PowerShell scripts have a .ps1 extension (along with other supported extensions such as psm1,psd1 etc) it will not run other extensions other than that.
I had also got the same issue when i am trying to run .sh files. The solution is you need to enable bash shell by typing bash.After enabling Bash on Windows, you can run .sh files by typing bash ./fileName.sh. But i have tried through git bash with typing . fileName.sh it worked well. These are the two solutions that I have found, and you can try whatever you wish.