Git bash notes

From raju

default font used by git bash

Lucida Console, 9-point

To use this in gvim

    set guifont=Lucida_Console:h9:cANSI
    

Note: Previously, I used

    set guifont=Lucida_Console:h9:cANSI:qDRAFT
    

Afterwards, find out what the :qDRAFT option at the end does.

PS1 in git bash

    # By default git bash sets the bash prompt to
    # $ echo $PS1
    # \[\033]0;$TITLEPREFIX:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[36m\]`__git_ps1`\[\033[0m\]\n$
    # which makes the system very slow. Change it to make it faster.
    export PS1='\[\033]0;$TITLEPREFIX:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[35m\]$MSYSTEM \[\033[33m\]\w\[\033[0m\]\n$'
    

Ref:- http://stackoverflow.com/questions/4485059/git-bash-is-extremely-slow-in-windows-7-x64

vim and gvim

    # for gvim
    # I want to use gvim custom installed in /c/Program\ Files\ \(x86\)/Vim/vim80/gvim.exe
    # and vim that comes with git bash (/usr/bin/vim).
    # There is no gvim in git bash. The vim in 
    # /c/Program\ Files\ \(x86\)/Vim/vim80/ cannot be run from git bash as it gives
    #   Vim: Error: This version of Vim does not run in a Cygwin terminal
    # As a work around add /c/Program\ Files\ \(x86\)/Vim/vim80 to the end of the
    # path.
    export PATH=$PATH:"/c/Program Files (x86)/Vim/vim80"
    

always background gvim

By default when gvim is run from git bash, the command prompt does not return. One way around this is to add '&' to background the job. But I always forget to do that. To work around this, I have the following in ~/.bashrc so gvim commands are always backgrounded.

    # Always background gvim
    gvim()
    {
        abs_gvim=`which gvim`
        "$abs_gvim" "$@" &
    }
    

Ref:- https://superuser.com/questions/569036/git-for-windows-run-vim-in-background-without-ampersand

This will break if gvim were to read from standard input (for example output of svn diff piped to gvim -). For that

    svn diff | "`which gvim`" - &
    

python setup

To pickup python installed via Anaconda, add the following lines to ~/.bashrc

    #------------------------------------------------------------------------------
    # Python setup
    export PATH=/c/ProgramData/Continuum/Anaconda/envs/py36:/c/ProgramData/Continuum/Anaconda/envs/py36/Scripts:$PATH
    alias python='winpty python.exe'
    alias python3="winpty python.exe"
    alias python2="winpty /c/ProgramData/Continuum/Anaconda/python.exe"
    #------------------------------------------------------------------------------
    
    #------------------------------------------------------------------------------
    # run programs with winpty
    w()
    {
        winpty "$@"
    }
    #------------------------------------------------------------------------------
    

Here conda installed python2 by default and I have a py36 environment for Python 3.6.

/c/ProgramData/Continuum/Anaconda/envs/py36 is used to pick up python 3 executables.

/c/ProgramData/Continuum/Anaconda/envs/py36/Scripts is used to pick up utilities such as csvsql from csvkit package.


See also: https://stackoverflow.com/questions/32597209/python-not-working-in-the-command-line-of-git-bash

set PYTHONPATH

To set it on the command line

    PYTHONPATH='C:/path/to/foo' python foo.py -h
    

To set it in a script

    #! /usr/bin/env bash
    
    export PYTHONPATH="C:/path/to/foo;$PYTHONPATH"
    

Sample bash script to run python

    #! /usr/bin/env bash
    
    export PYTHONPATH="C:/path/to/utils;$PYTHONPATH"
    C:/ProgramData/Continuum/Anaconda/python.exe C:/path/to/script.py --arg foo
    

open multiple websites in chrome

launch a git bash session form another git bash session

    $ winpty /c/Program\ Files/Git/Git\ Gui/git-bash.exe