How can I use oh-my-zsh with PHPStorm? - zsh

I just got oh-my-zsh (a very good command line utility) and would like to utilize this within the PHPStorm terminal. How can I accomplish this?

As oh-my-zsh is more of an extended zsh-configuration, it should be sufficient to just tell PHPStorm to use zsh as Shell. This can be done in the Settings dialog (Menu File->Settings) under section Project Settings->Terminal. Just change Shell Path to the path of zsh (can be found out with type zsh in a terminal).
To affect every (new) project you may have to repeat this in File->Default Settigs

For once and all setup:
Set it in Preferences->Tools->Terminal and Shell Path = /bin/zsh
restart your PhpStorm and thats it.

Related

Can I use zsh as the default non-interactive shell for WSL2 Ubuntu?

I am trying to use Run/Debug Configurations on WebStorm, however it doesn't seem to source .zshrc and produces errors about not finding commands and environment variables. (An example of this would be yarn tauri dev when using Tauri)
I have installed Ubuntu 20.04 in WSL and the project I opened in WebStorm resides under the $HOME directory. WebStorm is installed in Windows.
For the interactive shell, I have made zsh the default by chsh -s $(which zsh), but when using Run/Debug Configurations it uses the default non-interactive shell, which is dash as far as I know. And my environment variables and PATH are all set in .zshrc, which is not sourced by dash.
It seems in CLion, it is possible to execute commands in the login shell according to this YouTrack issue, but such an option is not available on WebStorm.
Is it possible to use zsh instead of dash as the default non-interactive shell? If not, it would help me a lot to know what is the best practice in such situations.
There are several questions and points you make:
First, from the question title (and the summary at the end):
Can I use zsh as the default non-interactive shell for WSL2 Ubuntu?
Well, maybe (using symlinks), but it would be a really bad idea. So many built-in scripts rely on /bin/sh pointing to Dash, or at least Bash. While Zsh might be compatible with 99.9% of them, eventually there's a strong likelihood that some difference in Zsh would cause a system-level script to fail (or at least produce results inconsistent with those from Dash).
It is possible in Ubuntu to change the default non-interactive ("system" shell) from Dash to Bash with sudo dpkg-reconfigure dash. If you select "No" in the resulting dialog, then the system will be updated to point /bin/sh to bash instead of dash.
But not to Zsh, no.
when using Run/Debug Configurations it uses the default non-interactive shell, which is dash as far as I know
I don't run WebStorm myself, so I'm not sure on this exactly. Maybe #lena's answer (or another) will cover it for you, but if it doesn't, I'm noticing this doc page. It might be worth trying to specify Zsh in those settings, but again, I can't be sure.
And my environment variables and PATH are all set in .zshrc, which is not sourced by dash.
Hmm. I'm guessing you would need these set in a .profile/.zprofile equivalent regardless. I would assume that WebStorm is executing the shell as a non-interactive one, which means that it wouldn't even parse ~/.bashrc if Bash was your default shell.
... it would help me a lot to know what is the best practice in such situations.
Best practice is probably to make sure that your ~/.profile has any environment changes needed. Yes, this violates DRY (don't repeat yourself), but it's probably the best route.
Thanks to the answer here and the discussion below, I was able to figure it out. (Thank you, #NotTheDr01ds and #lena.)
The main problem is that WebStorm is installed on Windows and therefore knows only the environment variables in Windows. There are two ways to solve the problem as follows.
Sharing WSL's environment variable to Windows through WSLENV
Add the line below to .zshrc so that it sets $WSLENV when zsh starts.
export WSLENV=VAR_I_WANT_TO_SHARE:$WSLENV
# Don't forget to insert the colon
# And for some reason, appending the variable after $WSLENV didn't work well
In Windows, run
wsl -e zsh -lic powershell.exe
This runs WSL using zsh (logged-in and interactive), then runs powershell which brings you back to Windows. Although this doesn't seem to achieve anything, by going through zsh in WSL, .zshrc was sourced and therefore $WSLENV set as well. You can check if it worked well by running the below command after you've run the above.
$env:VAR_I_WANT_TO_SHARE
Run WebStorm from the PowerShell that was just created.
& 'C:\Program Files (x86)\JetBrains\WebStorm 2022.1.3\bin\webstorm64.exe'
When you run or debug any of the Run/Debug Configurations, you will see that the environment variable is shared successfully.
Setting the PATH in Windows
For most environment variables, the previous method works well. However, PATH is an exception. The Windows PATH is shared to WSL by default. The opposite doesn't work, probably because the PATH in WSL should not interfere with Windows.I've tried adding the $PATH of WSL into $WSLENV but it didn't seem to work.
In the end, what I did was manually adding each needed $PATH of WSL into the Windows PATH.
For example, if there was export PATH=$PATH:home/(username)/.cargo/bin in .zshrc, you can then add \\wsl$\Ubuntu\home\(username)\.cargo\bin to the Windows $env:Path using the Environment Variable window.
I might have made some mistakes, so feel free to leave an edit or comments.
You can try using npm config set script-shell command to set the shell for your scripts. Like npm config set script-shell "/usr/bin/zsh".
When npm run <script name> spawns a child process, the SHELL being used depends on NPM environment. Cм https://docs.npmjs.com/cli/run-script:
The actual shell your script is run within is platform dependent. By
default, on Unix-like systems it is the /bin/sh command, on Windows it
is the cmd.exe. The actual shell referred to by /bin/sh also depends
on the system. As of npm#5.1.0 you can customize the shell with the
script-shell configuration
See also https://github.com/npm/npm-lifecycle/blob/10c0c08fc25fea3c18c7c030d4618a401963355a/index.js#L293-L304

What is the best way to set up zsh with oh-my-zsh, powerlevel10k and nvm?

I'm using zsh on Linux with OhMyZsh and the powerlevel10k theme. I'm also using nvm since I have to switch node versions for different projects.
I'd like to achieve that zsh automatically uses the node version set in the .nvmrc file (if one exists). That should be triggered when changing into a directory that has a .nvmrc file, but also when opening a terminal (e.g. opening a vscode project, the internal terminal should be set to the respective node version).
I tried the ohmyzsh nvm plugin (with export NVM_LAZY=true and export NVM_AUTOLOAD=true), but that causes this behavior with powerlevel10k when opening a terminal:
[WARNING]: Console output during zsh initialization detected.
When using Powerlevel10k with instant prompt, console output during zsh
initialization may indicate issues.
...
The zsh-nvm plugin works better (with export NVM_LAZY_LOAD=true and export NVM_AUTO_USE=true). It automatically changes the version when changing directories, however not when opening the terminal.
I achieved that by adding this line to my .zshrc file:
[ -s "./.nvmrc" ] && nvm use > /dev/null 2>&1
That does not cause the above mentioned powerlevel10k issue, however the terminal changes the look (applying the powerlevel10k theme) after a couple seconds. I guess that is because of loading nvm right away (and not lazy loading it anymore). If I open the terminal in a directory without .npmrc, it opens fast and with the p10k theme right away.
I can live with this setup, but it is still not ideal and feels hacky. Is there a better way to do it?
Just for reference, there is also this issue on the zsh-nvm github

Change terminal in Atom-editor's Platformio-Ide-Terminal on Windows

On Windows, default terminal for Atom's Platformio-Ide-Terminal is Powershell (at least, that is what I get without any configuration).
I would prefer a terminal using unix-type commands. I already have MINGW and CYGWIN installed.
How can I avoid opening a Powershell and opening another terminal type instead?
Set the default shell in:
Edit>>Settings>>Packages>>Platformio Ide Terminal>>Settings>>Shell Override
You can use the git's bash as proposed here as you probably already have git installed.
C:\Program Files\Git\bin\bash.exe
Step by Step Solution
Go the Setting-> Packages -> In Search Bar, search for the platformio.
Open platformio and go to Shell Override Option.
Put the following line as per as your Terminal Requirement
For cmd- C:\\WINDOWS\\System32\\cmd.exe
For Power Shell- C:\\WINDOWS\\Sysnative\\WndowsPowerShell\\v1.0\\powershell.exe
For bash- C:\\Program Files\\Git\\bin\\bash.exe or C:\\Windows\\System32\\bash.exe (depending on how you install the bash). Be Sure, that you have already install the bash into your computer.
Now, you can integrate bash, cmd, git bash, Power Shell into Atom using platformio as terminal.
For CYGWIN users, the bash executable from the following location has proved useful for setting the shell override Settings >> Packages >> Platformio Ide Terminal >> Settings >> Shell Override
C:\cygwin64\bin\bash.exe
If you are now using Ubuntu for Windows 10 (downloaded from the app store), you can change it to that as well.
Ubuntu gets installed in Windows' PATH by default, so just change the default shell to:
ubuntu.exe
That's it. Just remember that to get to your code, cd to /mnt/(driveletter)/wherever/your/files/sit.
For someone who still can't get this to work because your git bash is installed in AppData. This worked for me.
C:\Users\saurabh\AppData\Local\Programs\Git\bin\bash.exe

Can't open vim in zsh?

I recently decided to switch from zsh to bash. However, for some reason that escapes me, I cannot open vim within zsh after I change my default shell to zsh (chsh -s /bin/zsh). Currently, my default shell is bash. If I just use zsh to enter a zsh shell, I have no problems with vim. The problems arise when I try to change my default shell, then open a new terminal window. Any insight would be great as I'd love to be able to play around with zsh.
vim probably lives in a directory that is added to your PATH environment variable in one of your bash start up files. When you start zsh manually, that PATH is inherited by zsh. When you make zsh your default shell, it inherits a PATH which is not modified to include the directory for vim. In bash, type
which vim
to find out which directory vim lives in. Let's say it /usr/other/bin/. Then you would add the following to your .zshenv file (creating it if necessary):
path+=/usr/other/bin
New zsh sessions should now be able to run vim.

oh-my-zsh config file not loading

I am trying to get ZSH config working correctly on Mac OSX. I installed it using curl: curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh. Then I modified my zshrc file to fit my needs. It works only after I run source ~/.zshrc. But then if I come back and open a new tab or new terminal I have to do source ~/.zshrc to get the config settings to work again. Has anybody ran into this issue? I believe there is a way to make it so I don't have to do source ~/.zshrc with every new tab.
I figured this out. It was due to my config file. The part of the zsh config that wasn't loading needed to be moved down after the plugins load. After moving that it all worked as expected.
If you have themes like Powerlevel9k installed for your zsh shell then source the oh-my-zsh config file after the theme variable assignments in your .zshrc file like shown below.
Eg:
........
........
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=('status' 'load' 'ram_joined' 'time')
# source oh-my-zsh config
source $ZSH/oh-my-zsh.sh
Not the ideal solution but solves the issue:
Terminal -> Preferences -> Profiles -> Shells -> Startup
Check the box that says "Run command" and in the input box run
source ~/.zsh/.zshrc
This will be executed when you open a new terminal window / tab.
My final solution was to go to Terminal --> Preferences --> General --> Shells open with --> Command (complete path), and set it to /bin/zsh (or your path to zsh), and then set both New windows/tabs open with to "Same profile". It works fine for me.
My initial attempt was to go to Terminal --> Preferences --> Profiles, and in my default profile's "shell" tab's Startup section, I set it to run command "source ~/.zshrc". This also solved the problem of /.zshrc not loading, but it seemed tedious to see that command show on every terminal tab/window.
I had a similar problem. I found that I had long ago changed my Terminal preferences to run tcsh instead of the default login shell. Took me forever to figure this out!

Resources