Cygwin

Reason is the light and the light of life.

Jerry Su Apr 24, 2019 2 mins

Cygwin中安装软件

#download setup-x86_64.exe https://cygwin.com/setup-x86_64.exe
$ cd C:cygwin64
$ ./setup-x86_64.exe -q -P wget, tar, qawk, bzip2, subversion, vim, git
# git clone https://github.com/transcode-open/apt-cyg
$ cd apt-cyg
$ mv apt-cyg /usr/local/bin/
$ apt-cyg --help
$ cygcheck --help
# modify mirror
$ apt-cyg --mirror http://mirrors.163.com/cygwin
# mirrors backup 
# ftp://mirror.mcs.anl.gov/pub/cygwin
# http://mirrors.163.com/cygwin
# ftp://ftp.ges.redhat.com/private/releng/cygwin-1.8
# apt-cyg install man cygwin-doc
apt-cyg install vim screenwget subversion openssh

Pycahrm中启Cygwin终端

Files|Settings|Tools|Terminal|Shellpath path: C:\cygwin64\bin\bash.exe

This is a non-interactive shell, and does not source your profile. The next try is:

C:\cygwin64\bin\bash.exe --login -i

This produces an error from Pycharm that it cannot start the program correctly. A little checking says the leading command needs to be quoted, else Pycahrm treats the entire line as the name of the command, not as a command followed by flags. OK:

"C:\cygwin64\bin\bash.exe" --login -i

It starts in my home directory, not in my project root. Starting in the project root is one of the nice features of the terminal in IntelliJ. Finally, two changes. First the IntelliJ setting:

`"C:\cygwin64\bin\bash" -c "exec /usr/bin/env INTELLIJ=true $SHELL --login -i"
And an addition to my ~/.bashrc:

${INTELLIJ-false} && cd ${OLDPWD-.}

Cygwin中使用windows anaconda

vim ~/.bashrc加入以下脚本:

#####################By Jerry for using Anaconda on Cygwin#################

#  Anaconda Environment Selection - Plese set CONDA_BASE_DIR to the directory
#  containing the base installation of anaconda/miniconda.

export CONDA_BASE_DIR=/cygdrive/c/Users/YCKJ2939/AppData/Local/Continuum/anaconda3

#  Proxy Servers & Network Setup (if needed)

export HTTP_PROXY=
export HTTPS_PROXY=

#  IMPORTANT - Ignore carriage returns when using a Cygwin environment.

export SHELLOPTS
set -o igncr

###############################################################################

#  Manage conda environments for Python.  We check the environment variable
#  $CONDA_DEFAULT_ENV to see which environment is desired.  The default (base)
#  environment will be chosen if nothing is specified.  Note that this variable
#  will be explicitly managed by the cactivate ( ) function we have defined
#  below, specifically for the purpose of changing environments.  The root
#  environment is also handled slightly different from the others when it comes
#  to setting the CONDA_DEFAULT_ENV variable.

if [ ${CONDA_DEFAULT_ENV} ] && [ ${CONDA_DEFAULT_ENV} != 'base' ] 
then
    #  SELECT ONE OF THE NON-DEFAULT ENVIRONMENTS
    export CONDA_PREFIX=${CONDA_BASE_DIR}/envs/${CONDA_DEFAULT_ENV}
else
    #  SELECT THE DEFAULT ENVIRONMENT (and set CONDA_DEFAULT_ENV full path)
    export CONDA_DEFAULT_ENV=root
    export CONDA_PREFIX=${CONDA_BASE_DIR}
fi

###############################################################################

#  Define cconda and cactivate to facilitate management of conda.

alias cconda=${CONDA_BASE_DIR}/Scripts/conda.exe

cactivate() {
    export CONDA_DEFAULT_ENV=$1
    source ~/.bashrc
    cconda info --envs
}

###############################################################################

#  PATH - ALl of the anaconda/miniconda path entries appear first.

PATH=
PATH=$PATH:$CONDA_PREFIX
PATH=$PATH:$CONDA_PREFIX/Library/mingw-w64/bin
PATH=$PATH:$CONDA_PREFIX/Library/usr/bin
PATH=$PATH:$CONDA_PREFIX/Library/bin
PATH=$PATH:$CONDA_PREFIX/Scripts
PATH=$PATH:$HOME/scripts
PATH=$PATH:$HOME/local/bin
PATH=$PATH:/usr/local/bin
PATH=$PATH:/usr/bin

export PATH

###############################################################################

Somethings to remember for this integration to work.

  1. Please install Anaconda directly from installer and not from package manager like Chocolatey, since for this approach to work the envs must be within the anaconda root directory.

  2. In order for anaconda python to work in cygwin commandline, you must use python -i. Using just python freezes the screen.

Ref: using-anaconda-environments-with-cygwin-on-windows


Read more: