Skip to content

Instantly share code, notes, and snippets.

@deletosh
Created July 16, 2015 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deletosh/36c60aca43aef623ef55 to your computer and use it in GitHub Desktop.
Save deletosh/36c60aca43aef623ef55 to your computer and use it in GitHub Desktop.
Properly Setup Cygwin
# Properly Setup Cygwin
#### Moving your home directory to your Windows profile directory
I found this setup to be consistent with other unix systems. It preserves my sanity in the long run.
```
mkpasswd -l -d -p "$(cygpath -H)" > /etc/passwd
mkgroup -l -d > /etc/group
```
#### Installing Essential Programs
Download the setup.exe and install it along with wget. We will be using apt-cyg, which is similar to apt-get in Debian-based linux distros. It allows you to specify the packages you want to install right on the terminal:
```
wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
chmod +x apt-cyg
mv apt-cyg /usr/local/bin/
if [ $(uname -m) == 'i686' ]; then arch="x86"; else arch="x86_64"; fi; sed -i "s/\(wget -N \$mirror\)\(\/setup\..*\)/\1\/$arch\2/" /usr/local/bin/apt-cyg
apt-cyg -m ftp://mirrors.kernel.org/sources.redhat.com/cygwin/ ctags curl ftp gcc gcc-g++ install make mintty mysql mysqld openssl screen tar vim vim-common wget which
```
The line that starts with if is to fix the bug introduced by Cygwin distinguishing x86 and x64 in their setup.ini file. I wrote the script so that it does not accidentally make wrong changes in the future.
`-m` specifies which server to fetch the installation files from. The default one supplied by `apt-cyg` does not work. So I substituted it with `ftp://ftp.cygwinports.org/pub/cygwinports/` which is the most popular choice.
#### Better Terminal
I stick with [cmder](http://gooseberrycreative.com/cmder/)
Changing Shell from Bash to zsh
```
apt-cyg install zsh
```
On C:/cygwin/Cygwin.bat file or in your Terminal settings, set:
```
cygwin\bin\bash --login -i
```
to
```
cygwin\bin\zsh -l -i
```
or edit /etc/passwd file so that the shell with your name is set to `/bin/bash`
```
sed -i "s/$USER\:\/bin\/bash/$USER\:\/bin\/zsh/g" /etc/passwd
```
Don't use the automatic installer. If you do, you will have to delete the last line in .zshrc, because cygwin populates PATH for you anyway.
```
#Don't use this
curl -L https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh | sh
```
Use this instead:
```
git clone git://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh; if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then cp ~/.zshrc ~/.zshrc.orig; rm ~/.zshrc; fi
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
```
#### Disable bash completion
Bash completion, for some reason creates lag on cd. So I just disable it by renaming the directory.
mv /etc/bash_completion.d -v /etc/bash_completion.d_bak
#### Migration
if you are coming from bash shell, you would probably have .bashrc file that you would want to import. In my case importing was pretty easy. I grouped some `export`s and `shopt` under:
if [ -n "$BASH_VERSION" ]; then
...
fi
and then added the following line to .zshrc at the end.
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
I ignore .ntuser* files in the home directory because there is no way to hide them or move them. I have set the alias in the .bashrc file, but oh-my-zsh has alias to ls as well. Instead of commenting those out, it is simpler to just load .bashrc later.
Also zsh sources [].zprofile instead of .profile](http://superuser.com/questions/187639/zsh-not-hitting-profile). So I include the following line to launch screen when I open the terminal. (And run it only when screen is not already executing, it's not preference)
if [[ $(ps | grep screen | wc -l) == 0 && (-f /usr/bin/screen.exe || -f /usr/bin/scren) ]] ; then
screen -S s
fi
#### Customizing Zsh
I am fan of agnoster as it blends well with the powerline and solarized. Make sure to use a patched up font though..
Plugins for cygwin is a bit limited. Here are the ones I think could be useful:
cake coffee fabric gem npm perl per-directory-history pip rvm scala screen ssh-agent vagrant urlencode urldecode virtualenvwrapper web-search
I personally only added:
plugins=(git coffee fabric gem perl per-directory-history pip ssh-agent urlencode urldecode)
#### Multi-language support
remove the following line in the 'Cygwin.bat' in the cygwin folder
set LANG=en_US.UTF-8
and add something like the following line:
set LANG=ko_KR.eucKR
#### Installing TMux
I have recently switched from GNU screen to tmux. Four years ago when I was debating between the two, the latter choice was not available. The installation is super simple now, but there is one manual intervention that is necessary. The apt-cyg assumes that all packages it downloads are in bunzip format, but in case for tmux, the file is in So find the line that does the uncompression and change it temporarily. Oh and make sure to download the latest setup.exe from the cygwin website and run it to get the latest libraries.
vim $(which apt-cyg)
replace (around line 350)
cat $file | bunzip2 | tar > "/etc/setup/$pkg.lst" xvf - -C /
to
cat $file | tar > "/etc/setup/$pkg.lst" xJf - -C /
and run
apt-cyg install tmux
#### Color
I use solarized. The instruction and files are here https://github.com/karlin/mintty-colors-solarized
#### Tips for using Bash
Should you choose to use bash in cygwin, I recommend you to not use bash_completion. It will slow down your bash a lot. Just comment out a line like this in your .bash_profile or .bashrc
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
# . /etc/bash_completion
#fi
Other quirks
If you use gVim, it is possible that the PATH variable contains path to gVim earlier than the path to cygwin/bin. (If you installed gVim manually, it is recommended that you do add gVim to PATH to make your life easier for executing it) In this case when you execute vim from the command prompt, it will try to execute gvim and it might hang. You can check this by typing alias and seeing which executable is getting called. You do want gvim to be selected
Based on: http://www.4thinker.com/cygwin-setup.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment