POSIX for Windows

Stephen Y.F. Wang

2017-01-05


 

ConEmu

ConEmu is a Windows console emulator with tabs, which presents multiple consoles and simple GUI applications as one customizable GUI window with various features. ConEmu can be used with any other console application or simple GUI tools.

—- https://conemu.github.io/

With native windows commands, using ConEmu is same as CMD, but with lots of enhancement, you can also use MSYS within ConEmu with following steps:

  1. Download the msys terminal connector from https://conemu.github.io/en/CygwinMsysConnector.html
  2. Put it in /path2msys/bin
  3. Set a ConEmu Task as

    set CEMDIR=%ConEmuWorkDir% & cmd /k /path2msys/bin/conemu-msys-32.exe
    it will starts MSYS within ConEmu with current ConEmuWorkDir
  4. If want open ConEmu and MSYS within Atom, can try the plugins open-conemu-here and open-msys-here.

MSYS

MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. An example would be building a library that uses the autotools build system. Users will typically run ./configure then make to build it.

—- http://www.mingw.org/wiki/msys

An recently alternative is MSYS2, an independent rewrite of MSYS, based on modern Cygwin and MinGW-w64 with the aim of better interoperability with native Windows software. It works with the pacman package manager. A challenge with MSYS is that it works well with packages build within this environment, but may not be compatible with standard Windows system package, such as Python.

  1. Download: There are three places you can get MSYS
    1. The MinGW project, with separate packages of all official MSYS packages, may take a long time to download and install.
    2. The all-in-one package in the MinGW-w64 project.
    3. MinGW-builds provides an ultra-inclusive MSYS package with a bunch of additional useful stuff, such as msysgit and svn.

    I suggest the MinGW-builds version.

  2. Installation: Unzip the downloaded file to a folder, such as /c/msys.
  3. Settings:
    1. In /path2msys/etc, add a line with

      c:/TDM-GCC-64       /mingw

      if you want to use the TDM-GCC. it can be the path to any other GNU Toolchain you choose.

    2. If you want use the ConEmu as the terminal for MSYS, it is better to replace the cd "$HOME" with the following codes to the file /path2msys/etc/profile

      if [ -n "$CEMDIR" ]; then
        CEMDIR1=$(echo "$CEMDIR" | sed -e 's/\\/\//g' -e 's/://')
        cd "/$CEMDIR1"
      else
        cd "$HOME"
      fi
    3. You can add the /path2msys/bin to Windows Path, but this is not necessary, since you should always use MSYS command within MSYS environment.

GNU Toolchain

There are several versions of GNU Toolchain for Windows, include MinGw, MinGw-w64 and TDM-GCC. MinGw only can build 32 bit binaries, MinGw-w64 supports both 32 and 64 bit binaries, but need to install both versions, while TDM-GCC supports both 32 and 64 bit binaries with switching by adding one compile option. My choice is TDM-GCC.

The installation of TDM-GCC is similar to usual Windows programs, it is better to choose all packages, the gfortran is not installed by default.

Git

  1. Git Config

    # global username and email, the local one is associated with project
    git config --global user.name "username"
    git config --global user.email "useremail"
    # ssh key
    ssh-keygen -t rsa -f ~/.ssh/nameofrsafile -C "useremail"
    # put the key in server (github), then test with:
    ssh -T git@github.com

    if working with several servers, should use ssh config file, with contents like:

    Host github.com
    RSAAuthentication yes
    Port 22
    IdentityFile ~/.ssh/id_rsa_xxx
  2. Initialize a Git Project:

    cd /path2project
    git init
  3. Local Git

    # check status
    git status
    # add files
    git add <file>
    git add -A
    # commit
    git commit -m "information"
    # check log
    git log
    # remove changes
    git checkout -- .
    # check current file status and last commit
    git diff
    # versions
    git reflog
    git reset --hard versionid
  4. Github or other git server

    # Add Origin repo
    git remote add origin sshorhttps_address
    # if the server repo contains readme or license
    git push -u origin master
    # push local commit to server
    git push
    # get last commit from server
    git pull