How to use Z shell with your IntelliJ Idea on Windows with Cygwin
It is difficult to imagine modern development without daily work with the terminal, but often people who are familiar with the most powerful zsh and bash in Linux are forced to work on Windows machines, where cmd.exe
is used as default command prompt. We often are quite limited with privileges given, so today I will show you how to install and integrate Z shell with Intellij Idea, using Cygwin. All installed packages will not require any privilege escalation and will be transparent to compliance
We will need to follow these steps:
- Install cygwin
- Install cyg-apt
- Install zsh
- Install Idea
- Change default IntelliJ Idea cmd.exe terminal to Cygwin Zsh
Install Cygwin
Cygwin is a POSIX-compatible programming and runtime environment that runs natively on Microsoft Windows. With other words Cygwin is the replacement for basic cmd.exe
command prompt in Windows gives you native Unix look and feel
Please download the installer (I suppose you`re using x64 bit platform)
Then open cmd.exe and cd to the place where setup-x86_64.exe
is located. Assuming the path is C:\Users\Admin\Downloads
execute the installer with following command:
C:\Users\Admin\Downloads\setup-x86_64.exe --no-admin -q -P wget,tar,git,nano
You will have to choose mirror site (some of them really slow) and then installer will download all necessary packageswget,tar,git,nano
. You may also notice — no-admin
flag that eliminates admin priveleges requirement
Cyg-Apt
This is cygwin package manager. Well, this is not necessary, but believe me, you will suffer without it, so quick step how to install
Open cygwin terminal and type:
wget https://raw.githubusercontent.com/transcode-open/apt-cyg/master/apt-cyg > apt-cyg
install apt-cyg /bin
Done here
Install Zsh
The next step to use apt-cyg to install zsh package:
apt-cyg install zsh
When it`s done you should have zsh available, but we have another job to do. Zsh is basically meaningless without Oh My Zsh framework superpower, type
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
Now we are ready to test our shell
/bin/zsh
You should see now nice ZSH command line prompt. Feel free to take a look at ~/.zshrc and experiment with ZSH_THEME variable, you may spend a few hours and find theme you will be really happy with
Alright! At this point we have got one of the best shell at the current moment ready for duty, now it is time to bind it with one of the most advanced IDE`s
Install Intellij IDEA
We will use Community edition. Please download it, install, and we are ready for the last step
Change default IntelliJ Idea cmd.exe terminal to Cygwin ZSH
Run Idea, then open settings
File -> Settings (Ctrl+Alt+S) -> Tools -> Terminal -> Application Settings
Click browse button at “Shell path” and find your zsh.exe binary. Typically it should be something like “C:\cygwin64\bin\zsh.exe”
You have to add -li to the executable params in order to get your shell to work in interactive mode
Here the full string to enter
“C:\cygwin64\bin\zsh.exe” -li
One more thing you have to do. Cygwin will force the terminal to cd into it`s home folder every time you open new terminal tab. In order to work inside your current project dir you have to type
“CHERE_INVOKING=1” in Environment variables section above
Overall Terminal tab should look like shown in the picture
That`s it, now you can use your bright and shiny zsh without any need to leave IDE window
Bonus:
Like me you also probably work with multiple servers that you need to ssh into at any given time. Often they names are really weird and hard to remember
Now you can use awesome ZSH autocompletion on order to make your life really comfortable
Here is a quick snippet you may add to the end of your .zshrc file:
# Highlight the current autocomplete option
zstyle ‘:completion:*’ list-colors “${(s.:.)LS_COLORS}”# Better SSH/Rsync/SCP Autocomplete
zstyle ‘:completion:*:(scp|rsync):*’ tag-order ‘ hosts:-ipaddr:ip\ address hosts:-host:host files’
zstyle ‘:completion:*:(ssh|scp|rsync):*:hosts-host’ ignored-patterns ‘*(.|:)*’ loopback ip6-loopback localhost ip6-localhost broadcasthost
zstyle ‘:completion:*:(ssh|scp|rsync):*:hosts-ipaddr’ ignored-patterns ‘^(<->.<->.<->.<->|(|::)([[:xdigit:].]##:(#c,2))##(|%*))’ ‘127.0.0.<->’ ‘255.255.255.255’ ‘::1’ ‘fe80::*’# Allow for autocomplete to be case insensitive
zstyle ‘:completion:*’ matcher-list ‘’ ‘m:{[:lower:][:upper:]}={[:upper:][:lower:]}’ \
‘+l:|?=** r:|?=**’# Initialize the autocompletion
autoload -Uz compinit && compinit -i
Then source .zshrc or just close / open your terminal
Now when you will want to ssh to some server you can use following input pattern:
ssh user@<tab>
You will get list of all ssh servers available from history, will be able to choose one from list with arrow keys
Check here for additional details
Troubleshooting
You may find some wget / apt-cyg networking issues, as specially when you behind the corporate proxy firewall
In order to fix that edit your .bashrc and .zshrc files and add following lines at the end:
export http_proxy=username:password@proxyhost.com:8080
export https_proxy=username:password@proxyhost.com:8081
Conclusion
We are done right here. Now you will have all the power of linux on your Windows machine in portable format without any additional heavy solutions like WSL. Thank you, hope you will enjoy it!
References:
https://medium.com/@alllexsm/how-to-install-z-shell-zsh-on-cygwin-dd9ee380d783
https://www.codyhiar.com/blog/zsh-autocomplete-with-ssh-config-file/