Git bash notes
From raju
Note:- This page will be migrated to http://www.kamaraju.xyz/dk/git_bash_notes. Once that is done, it will be deleted.
install additional software in git bash
install software directly under /
This installs the tree package directly under /.
Download the xz file
mkdir -p ~/x/software cd ~/x/software curl http://repo.msys2.org/msys/x86_64/tree-1.8.0-1-x86_64.pkg.tar.xz --output tree-1.8.0-1-x86_64.pkg.tar.xz
Check the files in the archive
tar tf tree-1.8.0-1-x86_64.pkg.tar.xz
The next step will copy (and overwrite) these files to /.
tar xJvf tree-1.8.0-1-x86_64.pkg.tar.xz -C /
To uninstall, get a sense of files that will be deleted
cd / tar tf ~/x/software/tree-1.8.0-1-x86_64.pkg.tar.xz | xargs ls -1d 2> /dev/null
Delete the files
tar tf ~/x/software/tree-1.8.0-1-x86_64.pkg.tar.xz | xargs rm
Check the files that are not deleted (ex:- directories with files from other packages)
tar tf ~/x/software/tree-1.8.0-1-x86_64.pkg.tar.xz | xargs ls -1d 2> /dev/null
install rsync 3.1.3-1 into a non standard directory
http://www.kamaraju.xyz/dk/git_bash_notes#install_rsync_313-1_into_a_non_standard_directory
configure zsh installed in a non standard directory
Prerequisite: Install zsh into /opt/software/zsh by following install software into a non standard directory
Add this to ~/.bashrc so you can start zsh from bash shell
# For zsh export PATH=/opt/software/zsh/usr/bin:$PATH
Add this to ~/.zshenv
# Ref:- https://www.zsh.org/mla/users/2019/msg00125.html export MODULE_PATH=/opt/software/zsh/usr/lib/zsh/5.7.1:$MODULE_PATH # You should not export the $FPATH parameter. It is only needed by the # current shell process and not by any of its children. # Ref:- https://unix.stackexchange.com/a/33898/198064 FPATH=/opt/software/zsh/usr/share/zsh/functions/Completion:$FPATH
Add this to ~/.zshrc
export PS1="%n@%m:%d $"
dummy
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
website to download git for windows
- https://github.com/git-for-windows/git/releases/ - main website. If that is not working, try something like
- https://fossies.org/windows/misc/Git-2.15.0-64-bit.exe/ - alternate site to download 64-bit 2.15.0 version. If using this site, verify that the sha256sum matches with what is listed in the primary website.
debug slowness
$time echo $(__git_ps1)
git bash terminal as admin
In Windows Server 2012R2
Start menu -> down arrow button -> scroll to "Git Bash" icon" -> Right click on it -> Run as administrator
download git bash
- https://mirrors-wan.geekpie.club/git-for-windows - contains executables such as PortableGit-2.25.1-64-bit.7z.exe . Can be used if the official website does not work (ex:- due to corporate firewall).
- https://github.com/git-for-windows/git/releases - official